tizen beta release
[framework/web/wrt-plugins-common.git] / src / 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
28 class IStream;
29 typedef DPL::SharedPtr<IStream> IStreamPtr;
30
31 class IStream : private DPL::Noncopyable
32 {
33   public:
34     virtual ~IStream() = 0;
35
36     virtual IStreamPtr write(bool arg) = 0;
37     virtual IStreamPtr write(unsigned char arg) = 0;
38     virtual IStreamPtr write(char arg) = 0;
39     virtual IStreamPtr write(int arg) = 0;
40     virtual IStreamPtr write(double arg) = 0;
41     virtual IStreamPtr write(const std::string& arg) = 0;
42
43     virtual IStreamPtr read(bool& arg) = 0;
44     virtual IStreamPtr read(unsigned char& arg) = 0;
45     virtual IStreamPtr read(char& arg) = 0;
46     virtual IStreamPtr read(int& arg) = 0;
47     virtual IStreamPtr read(double& arg) = 0;
48     virtual IStreamPtr read(std::string& arg) = 0;
49
50     /**
51      * Gets characters from stream.
52      * @param num Number of characters to read.
53      * @return Pointer to read buffer.
54      * @throw PlatformException if stream is closed, EOF is set or write-only.
55      * @remarks Passes ownership to the caller.
56      */
57     virtual char* getChars(std::size_t num) = 0;
58
59     /**
60      * Gets bytes from stream.
61      * @param num Number of bytes to read.
62      * @return Pointer to read buffer.
63      * @remarks Passes ownership to the caller.
64      * @throw PlatformException if stream is closed, EOF is set or write-only.
65      */
66     virtual unsigned char* getBytes(std::size_t num) = 0;
67
68     /**
69      * Gets number of bytes read by last getBytes() or getChars() operation.
70      * @return Number of read bytes.
71      * @throw PlatformException if stream is closed or write-only.
72      */
73     virtual std::size_t getCount() const = 0;
74
75     /**
76      * Reads line of characters from stream (till '\n' character).
77      * @return Read line.
78      */
79     virtual std::string getLine() = 0;
80
81     /**
82      * Checks whether stream is open.
83      * @return True if stream is open, false otherwsie.
84      */
85     virtual bool isOpen() const = 0;
86
87     /**
88      * Checks whether End-Of-Line character occured.
89      * @return True if EOF flag was set, false otherwise.
90      */
91     virtual bool isEof() const = 0;
92
93     /**
94      * Closes stream.
95      */
96     virtual void close() = 0;
97
98     /**
99      * Gets current position in stream.
100      * @return Position or -1 if fails.
101      */
102     virtual long getPosition() const = 0;
103
104     /**
105      * Sets current position in stream.
106      * @param position Position to set.
107      */
108     virtual void setPosition(long position) = 0;
109
110     /**
111      * Gets mode stream was opened in.
112      * @return Mode @see Api::Filesystem::AccessMode.
113      */
114     virtual int getMode() const = 0;
115
116     /**
117      * Gets stream's size.
118      * @return Size or -1 if unavailable (e.g. stream is write-only).
119      */
120     virtual long getSize() const = 0;
121 };
122
123 } // API
124 } // Filesystem
125 } // WrtDeviceApis
126
127 #endif /* WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_ */