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 {
29 typedef DPL::SharedPtr<IStream> IStreamPtr;
31 class IStream : private DPL::Noncopyable
34 virtual ~IStream() = 0;
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;
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;
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.
57 virtual char* getChars(std::size_t num) = 0;
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.
66 virtual unsigned char* getBytes(std::size_t num) = 0;
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.
73 virtual std::size_t getCount() const = 0;
76 * Reads line of characters from stream (till '\n' character).
79 virtual std::string getLine() = 0;
82 * Checks whether stream is open.
83 * @return True if stream is open, false otherwsie.
85 virtual bool isOpen() const = 0;
88 * Checks whether End-Of-Line character occured.
89 * @return True if EOF flag was set, false otherwise.
91 virtual bool isEof() const = 0;
96 virtual void close() = 0;
99 * Gets current position in stream.
100 * @return Position or -1 if fails.
102 virtual long getPosition() const = 0;
105 * Sets current position in stream.
106 * @param position Position to set.
108 virtual void setPosition(long position) = 0;
111 * Gets mode stream was opened in.
112 * @return Mode @see Api::Filesystem::AccessMode.
114 virtual int getMode() const = 0;
117 * Gets stream's size.
118 * @return Size or -1 if unavailable (e.g. stream is write-only).
120 virtual long getSize() const = 0;
127 #endif /* WRTDEVICEAPIS_FILESYSTEM_ISTREAM_H_ */