commore  1.0.6-SNAPSHOT
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IOBStream.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2006-2014 Raphael David / CANTOR
3 //
4 
5 #ifndef CMR_BSTREAM_INCLUDED
6 #define CMR_BSTREAM_INCLUDED
7 
8 #include "Commore.h"
9 
10 #include <stdio.h>
11 
12 
13 namespace commore
14 {
18  struct BEndl {};
22  struct BFlush {};
25 
30  {
31  public:
32  IBStream();
33  ~IBStream();
37  IBStream(const AChar* s);
41  IBStream(const StringBuffer& s);
46  IBStream(const Path& file_path, bool text = true);
50  IBStream(const CommBuffer& buffer);
51 
52  public:
53  class Impl;
54 
55  public:
61  bool open(const Path& file_path, bool text = true);
66  bool open(const AChar* s);
71  bool open(const StringBuffer& s);
76  bool open(const CommBuffer& b);
80  bool is_open();
84  bool eof();
89  int get();
94  int get(char* dest, size_t len);
99  int peek();
103  void eatwhite();
107  const AChar* dump();
111  void close();
112 
113  protected:
115 
116  private:
117  IBStream(const IBStream&);
118  IBStream& operator=(IBStream&);
119 
120  };
121 
127  {
128  friend class OBStream;
129 
130  private:
131  ~OBStreamFormat();
132  OBStreamFormat(const OBStreamFormat& f);
133  public:
134  void add(const AChar* s) const;
135  void add(AChar c) const;
136  void add(const Char* s) const;
137  void add(Char c) const;
138  void add(const StringBuffer& s) const;
139  void add(int v) const;
140  void add(unsigned int v) const;
141  void add(bool v) const;
142  void add(const void* v) const;
143  void add(Float v) const;
144  void add(Double v) const;
145  void add(Long v) const;
146  void add(const TimePeriod& v) const;
147  void add(const TimeDate& v) const;
148 
149  private:
150  OBStreamFormat();
151  OBStreamFormat& operator=(const OBStreamFormat& f);
152  OBStreamFormat(OBStream& stream, const AChar* format);
153 
154  private:
155  void clear();
156  private:
157  OBStream* stream_;
158  const AChar* format_;
159  mutable OBStreamFormatArg* args_;
160 
161  };
162 
167  {
168  public:
169  OBStream();
175  OBStream(const Path& file_path, bool append = false, bool text = true);
179  OBStream(AString& s);
188  OBStream(CommBuffer& s, bool text);
189  ~OBStream();
190 
191  public:
192  class Impl;
193  public:
200  bool open(const Path& file_path, bool append = false, bool text = true);
205  bool open(AString& s);
210  bool open(StringBuffer& s);
216  bool open(CommBuffer& c, bool text);
220  bool is_open();
225  void put(int c);
230  void put(const char* s);
234  void flush();
240  void indent(int i = 1);
246  void unindent(int i = 1);
250  int get_indent();
254  int get_current_col();
258  OBStreamFormat format(const AChar* format);
262  OBStreamFormat operator()(const AChar* format);
267  void close();
268 
269  bool is_text() const;
270  protected:
272 
273  private:
274  OBStream(const OBStream&);
275  OBStream& operator=(OBStream&);
276 
277  };
281  CMREXD OBStream& bcout();
285  CMREXD IBStream& bcin();
289  CMREXD BEndl& bendl();
293  CMREXD BFlush& bflush();
294 };
295 
296 
303 
317 
318 
321 
322 #endif
CMREXD BFlush & bflush()
Definition: IOBStream.cpp:1168
Definition: IOBStream.cpp:32
Definition: AString.h:39
Definition: Time.h:21
Definition: StringBuffer.h:21
Impl * impl_
Definition: IOBStream.h:271
Definition: IOBStream.h:126
double Double
Definition: Type.h:46
char AChar
Definition: Type.h:65
OBStreamFormatArg * POBStreamFormatArg
Definition: IOBStream.h:23
#define CMREXD
Definition: Compiler.h:22
Definition: IOBStream.h:18
CMREXD IBStream & bcin()
Definition: IOBStream.cpp:1155
Definition: Path.h:19
Definition: CommBuffer.h:28
CMREXD BEndl & bendl()
Definition: IOBStream.cpp:1161
CMREXD commore::OBStream & operator<<(commore::OBStream &o, const char *s)
Definition: IOBStream.cpp:368
Definition: IOBStream.cpp:1226
float Float
Definition: Type.h:45
Definition: IOBStream.h:166
long long Long
Definition: Type.h:43
Definition: IOBStream.cpp:60
Definition: IOBStream.h:29
CMREXD OBStream & bcout()
Definition: IOBStream.cpp:1148
Impl * impl_
Definition: IOBStream.h:114
Definition: Time.h:261
Definition: IOBStream.h:22
wchar_t Char
Definition: Type.h:66