Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / modules / API / Filesystem / IStream.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 #ifndef WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_
17 #define WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_
18
19 #include <cstddef>
20 #include <string>
21 #include <dpl/noncopyable.h>
22 #include <dpl/shared_ptr.h>
23
24 namespace WrtDeviceApis {
25 namespace Filesystem {
26 namespace Api {
27 class IStream;
28 typedef DPL::SharedPtr<IStream> IStreamPtr;
29
30 class IStream : private DPL::Noncopyable
31 {
32   public:
33     virtual ~IStream() = 0;
34
35     virtual IStreamPtr write(bool arg) = 0;
36     virtual IStreamPtr write(unsigned char arg) = 0;
37     virtual IStreamPtr write(char arg) = 0;
38     virtual IStreamPtr write(int arg) = 0;
39     virtual IStreamPtr write(double arg) = 0;
40     virtual IStreamPtr write(const std::string& arg) = 0;
41
42     virtual IStreamPtr read(bool& arg) = 0;
43     virtual IStreamPtr read(unsigned char& arg) = 0;
44     virtual IStreamPtr read(char& arg) = 0;
45     virtual IStreamPtr read(int& arg) = 0;
46     virtual IStreamPtr read(double& arg) = 0;
47     virtual IStreamPtr read(std::string& arg) = 0;
48
49     /**
50      * Gets characters from stream.
51      * @param num Number of characters to read.
52      * @return Pointer to read buffer.
53      * @throw PlatformException if stream is closed, EOF is set or write-only.
54      * @remarks Passes ownership to the caller.
55      */
56     virtual char* getChars(std::size_t num) = 0;
57
58     /**
59      * Gets bytes from stream.
60      * @param num Number of bytes to read.
61      * @return Pointer to read buffer.
62      * @remarks Passes ownership to the caller.
63      * @throw PlatformException if stream is closed, EOF is set or write-only.
64      */
65     virtual unsigned char* getBytes(std::size_t num) = 0;
66
67     /**
68      * Gets number of bytes read by last getBytes() or getChars() operation.
69      * @return Number of read bytes.
70      * @throw PlatformException if stream is closed or write-only.
71      */
72     virtual std::size_t getCount() const = 0;
73
74     /**
75      * Reads line of characters from stream (till '\n' character).
76      * @return Read line.
77      */
78     virtual std::string getLine() = 0;
79
80     /**
81      * Checks whether stream is open.
82      * @return True if stream is open, false otherwsie.
83      */
84     virtual bool isOpen() const = 0;
85
86     /**
87      * Checks whether End-Of-Line character occured.
88      * @return True if EOF flag was set, false otherwise.
89      */
90     virtual bool isEof() const = 0;
91
92     /**
93      * Closes stream.
94      */
95     virtual void close() = 0;
96
97     /**
98      * Gets current position in stream.
99      * @return Position or -1 if fails.
100      */
101     virtual long getPosition() const = 0;
102
103     /**
104      * Sets current position in stream.
105      * @param position Position to set.
106      */
107     virtual void setPosition(long position) = 0;
108
109     /**
110      * Gets mode stream was opened in.
111      * @return Mode @see Api::Filesystem::AccessMode.
112      */
113     virtual int getMode() const = 0;
114
115     /**
116      * Gets stream's size.
117      * @return Size or -1 if unavailable (e.g. stream is write-only).
118      */
119     virtual long getSize() const = 0;
120 };
121 } // API
122 } // Filesystem
123 } // WrtDeviceApis
124
125 #endif /* WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_ */