[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / file-stream.h
1 #ifndef DALI_FILE_STREAM_H
2 #define DALI_FILE_STREAM_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <stdint.h>
22 #include <stdio.h>
23
24 #include <iostream>
25 #include <memory>
26 #include <string>
27
28 // INTERNAL INCLUDES
29 #include <dali/public-api/common/dali-vector.h>
30 #include <dali/public-api/dali-adaptor-common.h>
31
32 namespace Dali
33 {
34 class DALI_ADAPTOR_API FileStream
35 {
36 public:
37   /**
38    * @brief File type formats
39    * The default format is binary
40    */
41   enum FileMode ///< FileType format
42   {
43     BINARY = 1 << 0, ///< File stream will be opened as a binary
44     TEXT   = 1 << 1, ///< File stream will be opened as text
45     READ   = 1 << 2, ///< File stream will be opened for reading
46     WRITE  = 1 << 3, ///< File stream will be opened for writing
47     APPEND = 1 << 4, ///< File stream will be opened for appending
48   };
49
50   /**
51    * Constructor
52    * @param[in] filename Filename of the file to open the stream for
53    * @param[in] mode How we want to open the stream. Binary or Text, Read or Write. Binary & Read default
54    */
55   FileStream(const std::string& filename, uint8_t mode = BINARY | READ);
56
57   /**
58    * Constructor
59    * @param[in] buffer Buffer to open the stream for.
60    *                   The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
61    * @param[in] dataSize The maximum size of the data in the buffer.
62    * @param[in] mode How we want to open the stream. Binary or Text, Read or Write. Binary & Read default
63    */
64   FileStream(uint8_t* buffer, size_t dataSize, uint8_t mode = BINARY | READ);
65
66   /**
67    * Constructor
68    * @param[in] buffer Buffer to open the stream for.
69    *                   The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
70    * @param[in] dataSize The maximum size of the data in the buffer.
71    * @param[in] mode How we want to open the stream. Binary or Text, Read or Write. Binary & Read default
72    */
73   FileStream(Dali::Vector<uint8_t>& buffer, size_t dataSize, uint8_t mode = BINARY | READ);
74
75   /**
76    * Default move constructor
77    */
78   FileStream(FileStream&&);
79
80   /**
81    * Non copyable
82    */
83   FileStream(const FileStream&) = delete;
84
85   /**
86    * Non assignable
87    */
88   FileStream& operator=(const FileStream&) = delete;
89
90   /**
91    * Move assignable
92    */
93   FileStream& operator=(FileStream&&);
94
95   /**
96    * Destructor
97    */
98   ~FileStream();
99
100   /**
101    * @brief Returns the stream
102    * @return std::iostream.
103    */
104   std::iostream& GetStream();
105
106   /**
107    * @brief Returns the file stream
108    * @return FILE.
109    * @note This class is responsible for closing the file so the caller SHOULD NOT call fclose() on the returned pointer.
110    */
111   FILE* GetFile();
112
113 private:
114   class Impl;
115   std::unique_ptr<Impl> mImpl;
116 };
117
118 } // namespace Dali
119
120 #endif // DALI_FILE_STREAM_H