xmscore  1.0
daStreamIo.h
Go to the documentation of this file.
1 #pragma once
2 //------------------------------------------------------------------------------
7 //------------------------------------------------------------------------------
8 
9 //----- Included files ---------------------------------------------------------
10 // 3. Standard Library Headers
11 #include <sstream>
12 
13 // 4. External Library Headers
14 
15 // 5. Shared Headers
18 #include <xmscore/stl/vector.h>
19 
20 // 6. Non-shared Headers
21 
22 //----- Forward declarations ---------------------------------------------------
23 
24 //----- Namespace declaration --------------------------------------------------
25 
26 namespace xms
27 {
28 //----- Constants / Enumerations -----------------------------------------------
29 
30 //----- Forward declarations ---------------------------------------------------
31 
32 //----- Structs / Classes ------------------------------------------------------
33 
36 {
37 public:
38  explicit DaStreamReader(std::istream& a_inStream, bool a_binaryArrays = false);
40 
41  bool IsBinary() const;
42 
43  bool ReadNamedLine(const char* a_name);
44  bool ReadLine(std::string& a_line);
45  bool ReadStringLine(const char* a_name, std::string& a_val);
46  bool ReadIntLine(const char* a_name, int& a_val);
47  bool ReadDoubleLine(const char* a_name, double& a_val);
48 
49  bool ReadVecInt(const char* a_name, VecInt& a_vec);
50  bool ReadVecDbl(const char* a_name, VecDbl& a_vec);
51  bool ReadVecPt3d(const char* a_name, VecPt3d& a_vec);
52 
53  bool Read2StringLine(const char* a_name, std::string& a_val1, std::string& a_val2);
54  bool Read3StringLine(const char* a_name,
55  std::string& a_val1,
56  std::string& a_val2,
57  std::string& a_val3);
58  bool Read3DoubleLine(const char* a_name, double& a_val1, double& a_val2, double& a_val3);
59 
60  static bool ReadIntFromLine(std::string& a_line, int& a_val);
61  static bool ReadStringFromLine(std::string& a_line, std::string& a_val);
62  static bool ReadDoubleFromLine(std::string& a_line, double& a_val);
63 
64  bool ReadString(std::string& a_val);
65  bool ReadInt(int& a_val);
66  bool NextLine();
67 
68  bool ReadBinaryBytes(char* a_dest, long long a_destLength);
69 
70  bool LineBeginsWith(const char* a_text);
71 
72 private:
74  class Impl;
75  std::unique_ptr<Impl> m_impl;
76 };
77 
80 {
81 public:
82  explicit DaStreamWriter(std::ostream& a_outStream, bool a_binaryArrays = false);
83  ~DaStreamWriter();
84 
85  bool IsBinary() const;
86 
87  void WriteLine(const std::string& a_line);
88  void WriteStringLine(const char* a_name, const std::string& a_val);
89  void WriteIntLine(const char* a_name, int a_val);
90  void WriteDoubleLine(const char* a_name, double a_val);
91 
92  void WriteVecInt(const char* a_name, const VecInt& a_vec);
93  void WriteVecDbl(const char* a_name, const VecDbl& a_vec);
94  void WriteVecPt3d(const char* a_name, const VecPt3d& a_points);
95 
96  void Write2StringLine(const char* a_name, const std::string& a_val1, const std::string& a_val2);
97  void Write3StringLine(const char* a_name,
98  const std::string& a_val1,
99  const std::string& a_val2,
100  const std::string& a_val3);
101  void Write3DoubleLine(const char* a_name,
102  const double& a_val1,
103  const double& a_val2,
104  const double& a_val3);
105 
106  void WriteString(const char* a_string);
107  void AppendInt(int a_val);
108  void AppendInts(const int* a_vals, int a_numVals);
109  void AppendString(const std::string& a_val);
110  void EndLine();
111 
112  bool WriteBinaryBytes(const char* a_source, long long a_sourceLength);
113  void SetBinaryBlockSize(int a_blockSize);
114 
115 private:
116  XM_DISALLOW_COPY_AND_ASSIGN(DaStreamWriter)
117  class Impl;
118  std::unique_ptr<Impl> m_impl;
119 };
120 
121 //----- Function prototypes ----------------------------------------------------
122 
123 bool daReadNamedLine(std::istream& a_inStream, const char* a_name);
124 bool daReadLine(std::istream& a_inStream, std::string& a_line);
125 bool daReadIntLine(std::istream& a_inStream, const char* a_name, int& a_val);
126 bool daReadDoubleLine(std::istream& a_inStream, const char* a_name, double& a_val);
127 bool daReadStringLine(std::istream& a_inStream, const char* a_name, std::string& a_val);
128 bool daReadVecInt(std::istream& a_inStream, const char* a_name, VecInt& a_vec);
129 bool daReadVecDbl(std::istream& a_inStream, const char* a_name, VecDbl& a_vec);
130 bool daReadVecPt3d(std::istream& a_inStream, const char* a_name, VecPt3d& a_vec);
131 bool daRead2StringLine(std::istream& a_inStream,
132  const char* a_name,
133  std::string& a_val1,
134  std::string& a_val2);
135 bool daRead3StringLine(std::istream& a_inStream,
136  const char* a_name,
137  std::string& a_val1,
138  std::string& a_val2,
139  std::string& a_val3);
140 bool daRead3DoubleLine(std::istream& a_inStream,
141  const char* a_name,
142  double& a_val1,
143  double& a_val2,
144  double& a_val3);
145 
146 bool daReadIntFromLine(std::string& a_line, int& a_val);
147 bool daReadStringFromLine(std::string& a_line, std::string& a_val);
148 bool daReadDoubleFromLine(std::string& a_line, double& a_val);
149 
150 bool daLineBeginsWith(std::istream& a_inStream, const std::string& a_text);
151 
152 void daWriteVecInt(std::ostream& a_outStream, const char* a_name, const VecInt& a_vec);
153 void daWriteVecDbl(std::ostream& a_outStream, const char* a_name, const VecDbl& a_vec);
154 void daWriteVecPt3d(std::ostream& a_outStream, const char* a_name, const VecPt3d& a_points);
155 
156 void daWriteIntLine(std::ostream& a_outStream, const char* a_name, int a_val);
157 
158 void daWriteDoubleLine(std::ostream& a_outStream, const char* a_name, double a_val);
159 void daWrite3DoubleLine(std::ostream& a_outStream,
160  const char* a_name,
161  const double& a_val1,
162  const double& a_val2,
163  const double& a_val3);
164 
165 void daWriteLine(std::ostream& a_outStream, const std::string& a_line);
166 void daWriteStringLine(std::ostream& a_outStream, const char* a_name, const std::string& a_val);
167 void daWrite2StringLine(std::ostream& a_outStream,
168  const char* a_name,
169  const std::string& a_val1,
170  const std::string& a_val2);
171 void daWrite3StringLine(std::ostream& a_outStream,
172  const char* a_name,
173  const std::string& a_val1,
174  const std::string& a_val2,
175  const std::string& a_val3);
176 
177 } // namespace xms
Class for reading ASCII files with named card fields. Also includes the ability to embed non-portable...
Definition: daStreamIo.h:35
std::vector< int > VecInt
short rename
Definition: vector.h:27
bool ReadString(std::string &a_val)
Read a white space separated string.
Definition: daStreamIo.cpp:634
bool ReadVecDbl(const char *a_name, VecDbl &a_vec)
Read named vector of doubles from multiple lines.
Definition: daStreamIo.cpp:487
std::vector< double > VecDbl
short rename
Definition: vector.h:25
std::unique_ptr< Impl > m_impl
Implementation.
Definition: daStreamIo.h:74
bool ReadInt(int &a_val)
Read an integer value.
Definition: daStreamIo.cpp:644
bool IsBinary() const
Are array values read as binary?
Definition: daStreamIo.cpp:370
bool ReadIntLine(const char *a_name, int &a_val)
Read a named integer value from a line.
Definition: daStreamIo.cpp:435
bool ReadStringLine(const char *a_name, std::string &a_val)
Read a named string value from a line.
Definition: daStreamIo.cpp:455
static bool ReadDoubleFromLine(std::string &a_line, double &a_val)
Read a double value from a string. Return the remaining string.
Definition: daStreamIo.cpp:625
bool ReadLine(std::string &a_line)
Read a line from a stream with the following line endings: CR LF, LF, CR, or none.
Definition: daStreamIo.cpp:390
bool ReadDoubleLine(const char *a_name, double &a_val)
Read a named double value from a line.
Definition: daStreamIo.cpp:445
bool ReadVecInt(const char *a_name, VecInt &a_vec)
Read named vector of integers from multiple lines.
Definition: daStreamIo.cpp:465
bool ReadNamedLine(const char *a_name)
Read a line that begins with a name.
Definition: daStreamIo.cpp:379
bool Read3DoubleLine(const char *a_name, double &a_val1, double &a_val2, double &a_val3)
Read a named triplet of doubles from a line.
Definition: daStreamIo.cpp:583
Macros etc that make boost more convenient to use.
Implementation for DaStreamReader.
Definition: daStreamIo.cpp:53
bool ReadBinaryBytes(char *a_dest, long long a_destLength)
Read binary bytes of a given length from a file.
Definition: daStreamIo.cpp:665
static bool ReadIntFromLine(std::string &a_line, int &a_val)
Read an integer value from a string. Return the remaining string.
Definition: daStreamIo.cpp:596
bool Read3StringLine(const char *a_name, std::string &a_val1, std::string &a_val2, std::string &a_val3)
Read a named triplet of words from a line.
Definition: daStreamIo.cpp:568
#define XM_DISALLOW_COPY_AND_ASSIGN(TypeName)
A macro to disallow the copy constructor and operator= functions. This should be used in the private:...
Definition: base_macros.h:21
DaStreamReader(std::istream &a_inStream, bool a_binaryArrays=false)
Constructor.
Definition: daStreamIo.cpp:356
bool LineBeginsWith(const char *a_text)
Determines if next line read will begin given text.
Definition: daStreamIo.cpp:704
Vector types for convenience.
static bool ReadStringFromLine(std::string &a_line, std::string &a_val)
Read a string value from a string. Return the remaining string.
Definition: daStreamIo.cpp:606
bool ReadVecPt3d(const char *a_name, VecPt3d &a_vec)
Read named vector of Pt3d from multiple lines.
Definition: daStreamIo.cpp:509
bool NextLine()
Go to the next line in the stream.
Definition: daStreamIo.cpp:653
Class for writing ASCII files with named card fields. Also includes the ability to embed non-portable...
Definition: daStreamIo.h:79
bool Read2StringLine(const char *a_name, std::string &a_val1, std::string &a_val2)
Read a named pair of words from a line.
Definition: daStreamIo.cpp:556
~DaStreamReader()
Destructor.
Definition: daStreamIo.cpp:363
std::vector< Pt3d > VecPt3d
short rename
Definition: vector.h:51
Macros used in xmscore.