Fix the crash when it assumes the platform does not support multiple windows as GL...
[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 <stdio.h>
22 #include <stdint.h>
23
24 #include <iostream>
25 #include <string>
26 #include <memory>
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
35 class DALI_ADAPTOR_API FileStream
36 {
37 public:
38
39   /**
40    * @brief File type formats
41    * The default format is binary
42    */
43   enum FileMode  ///< FileType format
44   {
45     BINARY = 1 << 0,      ///< File stream will be opened as a binary
46     TEXT   = 1 << 1,      ///< File stream will be opened as text
47     READ   = 1 << 2,      ///< File stream will be opened for reading
48     WRITE  = 1 << 3,      ///< File stream will be opened for writing
49     APPEND = 1 << 4,      ///< File stream will be opened for appending
50   };
51
52   /**
53    * Constructor
54    * @param[in] filename Filename of the file to open the stream for
55    * @param[in] mode How we want to open the stream. Binary or Text, Read or Write. Binary & Read default
56    */
57   FileStream(const std::string& filename, uint8_t mode = BINARY | READ);
58
59   /**
60    * Constructor
61    * @param[in] buffer Buffer to open the stream for.
62    *                   The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
63    * @param[in] dataSize The maximum size of the data in the buffer.
64    * @param[in] mode How we want to open the stream. Binary or Text, Read or Write. Binary & Read default
65    */
66   FileStream(uint8_t* buffer, size_t dataSize, uint8_t mode = BINARY | READ);
67
68   /**
69    * Constructor
70    * @param[in] buffer Buffer to open the stream for.
71    *                   The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
72    * @param[in] dataSize The maximum size of the data in the buffer.
73    * @param[in] mode How we want to open the stream. Binary or Text, Read or Write. Binary & Read default
74    */
75   FileStream(Dali::Vector<uint8_t>& buffer, size_t dataSize, uint8_t mode = BINARY | READ);
76
77   /**
78    * Default move constructor
79    */
80   FileStream(FileStream&&);
81
82   /**
83    * Non copyable
84    */
85   FileStream(const FileStream&) = delete;
86
87   /**
88    * Non assignable
89    */
90   FileStream& operator=(const FileStream&) = delete;
91
92   /**
93    * Move assignable
94    */
95   FileStream& operator=(FileStream&&);
96
97   /**
98    * Destructor
99    */
100   ~FileStream();
101
102   /**
103    * @brief Returns the stream
104    * @return std::iostream.
105    */
106   std::iostream& GetStream();
107
108   /**
109    * @brief Returns the file stream
110    * @return FILE.
111    * @note This class is responsible for closing the file so the caller SHOULD NOT call fclose() on the returned pointer.
112    */
113   FILE* GetFile();
114
115 private:
116
117   struct Impl;
118   std::unique_ptr<Impl> mImpl;
119 };
120
121 } // Dali
122
123 #endif // DALI_FILE_STREAM_H