2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_
17 #define WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_
21 #include <dpl/noncopyable.h>
22 #include <dpl/shared_ptr.h>
24 namespace WrtDeviceApis {
25 namespace Filesystem {
28 typedef DPL::SharedPtr<IStream> IStreamPtr;
30 class IStream : private DPL::Noncopyable
33 virtual ~IStream() = 0;
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;
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;
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.
56 virtual char* getChars(std::size_t num) = 0;
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.
65 virtual unsigned char* getBytes(std::size_t num) = 0;
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.
72 virtual std::size_t getCount() const = 0;
75 * Reads line of characters from stream (till '\n' character).
78 virtual std::string getLine() = 0;
81 * Checks whether stream is open.
82 * @return True if stream is open, false otherwsie.
84 virtual bool isOpen() const = 0;
87 * Checks whether End-Of-Line character occured.
88 * @return True if EOF flag was set, false otherwise.
90 virtual bool isEof() const = 0;
95 virtual void close() = 0;
98 * Gets current position in stream.
99 * @return Position or -1 if fails.
101 virtual long getPosition() const = 0;
104 * Sets current position in stream.
105 * @param position Position to set.
107 virtual void setPosition(long position) = 0;
110 * Gets mode stream was opened in.
111 * @return Mode @see Api::Filesystem::AccessMode.
113 virtual int getMode() const = 0;
116 * Gets stream's size.
117 * @return Size or -1 if unavailable (e.g. stream is write-only).
119 virtual long getSize() const = 0;
125 #endif /* WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_ */