FFBinaryStream.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef GNSSTK_FFBINARYSTREAM_HPP
45 #define GNSSTK_FFBINARYSTREAM_HPP
46 
47 #include "FFStream.hpp"
48 #include "BinUtils.hpp"
49 
50 namespace gnsstk
51 {
53 
54 
60  class FFBinaryStream : public FFStream
61  {
62  public:
65 
67  virtual ~FFBinaryStream();
68 
74  FFBinaryStream(const char* fn,
75  std::ios::openmode mode=std::ios::in|std::ios::binary);
76 
78  virtual void open(const char* fn, std::ios::openmode mode);
79 
87  inline void getData(uint8_t& v);
88  inline void getData(uint16_t& v);
89  inline void getData(uint32_t& v);
90  inline void getData(uint64_t& v);
91  inline void getData(int8_t& v);
92  inline void getData(int16_t& v);
93  inline void getData(int32_t& v);
94  inline void getData(int64_t& v);
95  inline void getData(float& v);
96  inline void getData(double& v);
97 
104  void getData(char* buff, size_t length);
105 
113  inline void writeData(uint8_t v);
114  inline void writeData(uint16_t v);
115  inline void writeData(uint32_t v);
116  inline void writeData(uint64_t v);
117  inline void writeData(int8_t v);
118  inline void writeData(int16_t v);
119  inline void writeData(int32_t v);
120  inline void writeData(int64_t v);
121  inline void writeData(float v);
122  inline void writeData(double v);
124  void writeData(const char* buff, size_t length);
125 
130  virtual bool isStreamLittleEndian() const noexcept = 0;
131 
132  };
134 
135 
136 // Macro because all the getData functions are basically the same.
137 // Use a character buffer because typed data can have bad side effects
138 // causing data corruption.
139 #define FFBIN_GET_DATA(ITOH_FN,NTOH_FN) \
140  char buf[sizeof(v)] = ""; \
141  getData(buf, sizeof(v)); \
142  if (isStreamLittleEndian()) \
143  BinUtils::ITOH_FN(buf, v); \
144  else \
145  BinUtils::NTOH_FN(buf, v);
146 
147 #define FFBIN_WRITE_DATA(HTOI_FN,HTON_FN) \
148  char buf[sizeof(v)]; \
149  if (isStreamLittleEndian()) \
150  BinUtils::HTOI_FN(buf, v); \
151  else \
152  BinUtils::HTON_FN(buf, v); \
153  writeData(buf, sizeof(v));
154 
155 
156  inline void FFBinaryStream :: getData(uint8_t& v)
157  {
158  char *buf = reinterpret_cast<char*>(&v);
159  getData(buf, sizeof(v));
160  }
161 
162  inline void FFBinaryStream :: getData(uint16_t& v)
163  {
165  }
166 
167  inline void FFBinaryStream :: getData(uint32_t& v)
168  {
170  }
171 
172  inline void FFBinaryStream :: getData(uint64_t& v)
173  {
175  }
176 
177  inline void FFBinaryStream :: getData(int8_t& v)
178  {
179  char *buf = reinterpret_cast<char*>(&v);
180  getData(buf, sizeof(v));
181  }
182 
183  inline void FFBinaryStream :: getData(int16_t& v)
184  {
186  }
187 
188  inline void FFBinaryStream :: getData(int32_t& v)
189  {
191  }
192 
193  inline void FFBinaryStream :: getData(int64_t& v)
194  {
196  }
197 
198  inline void FFBinaryStream :: getData(float& v)
199  {
201  }
202 
203  inline void FFBinaryStream :: getData(double& v)
204  {
206  }
207 
208 
209  inline void FFBinaryStream :: writeData(uint8_t v)
210  {
211  char *buf = reinterpret_cast<char*>(&v);
212  writeData(buf, sizeof(v));
213  }
214 
215  inline void FFBinaryStream :: writeData(uint16_t v)
216  {
218  }
219 
220  inline void FFBinaryStream :: writeData(uint32_t v)
221  {
223  }
224 
225  inline void FFBinaryStream :: writeData(uint64_t v)
226  {
228  }
229 
230  inline void FFBinaryStream :: writeData(int8_t v)
231  {
232  char *buf = reinterpret_cast<char*>(&v);
233  writeData(buf, sizeof(v));
234  }
235 
236  inline void FFBinaryStream :: writeData(int16_t v)
237  {
239  }
240 
241  inline void FFBinaryStream :: writeData(int32_t v)
242  {
244  }
245 
246  inline void FFBinaryStream :: writeData(int64_t v)
247  {
249  }
250 
251  inline void FFBinaryStream :: writeData(float v)
252  {
254  }
255 
256  inline void FFBinaryStream :: writeData(double v)
257  {
259  }
260 
261 }
262 #endif
gnsstk::BinUtils::buitohsl
void buitohsl(const void *p, int32_t &v, unsigned pos=0)
Definition: BinUtils.hpp:635
gnsstk::BinUtils::buitohs
void buitohs(const void *p, uint16_t &v, unsigned pos=0)
Definition: BinUtils.hpp:574
gnsstk::FFBinaryStream::open
virtual void open(const char *fn, std::ios::openmode mode)
Overrides open to ensure binary mode opens.
Definition: FFBinaryStream.cpp:71
gnsstk::BinUtils::buntohsll
void buntohsll(const void *p, int64_t &v, unsigned pos=0)
Definition: BinUtils.hpp:783
gnsstk::FFStream
Definition: FFStream.hpp:119
gnsstk::BinUtils::buntohd
void buntohd(const void *p, double &v, unsigned pos=0)
Definition: BinUtils.hpp:818
gnsstk::BinUtils::buhtonl
void buhtonl(void *p, uint32_t v, unsigned pos=0)
Definition: BinUtils.hpp:983
gnsstk::BinUtils::buhtoid
void buhtoid(void *p, double v, unsigned pos=0)
Definition: BinUtils.hpp:950
gnsstk::BinUtils::buhtoiss
void buhtoiss(void *p, int16_t v, unsigned pos=0)
Definition: BinUtils.hpp:885
gnsstk::FFBinaryStream
Definition: FFBinaryStream.hpp:60
gnsstk::BinUtils::buhtond
void buhtond(void *p, double v, unsigned pos=0)
Definition: BinUtils.hpp:1082
gnsstk::BinUtils::buhtonll
void buhtonll(void *p, uint64_t v, unsigned pos=0)
Definition: BinUtils.hpp:998
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::BinUtils::buitohss
void buitohss(const void *p, int16_t &v, unsigned pos=0)
Definition: BinUtils.hpp:621
gnsstk::BinUtils::buhtonss
void buhtonss(void *p, int16_t v, unsigned pos=0)
Definition: BinUtils.hpp:1017
gnsstk::BinUtils::buntohl
void buntohl(const void *p, uint32_t &v, unsigned pos=0)
Definition: BinUtils.hpp:719
gnsstk::BinUtils::buhtonsl
void buhtonsl(void *p, int32_t v, unsigned pos=0)
Definition: BinUtils.hpp:1031
gnsstk::BinUtils::buntohss
void buntohss(const void *p, int16_t &v, unsigned pos=0)
Definition: BinUtils.hpp:753
gnsstk::BinUtils::buitohsll
void buitohsll(const void *p, int64_t &v, unsigned pos=0)
Definition: BinUtils.hpp:651
FFBIN_GET_DATA
#define FFBIN_GET_DATA(ITOH_FN, NTOH_FN)
Definition: FFBinaryStream.hpp:139
gnsstk::BinUtils::buhtois
void buhtois(void *p, uint16_t v, unsigned pos=0)
Definition: BinUtils.hpp:838
gnsstk::BinUtils::buntohll
void buntohll(const void *p, uint64_t &v, unsigned pos=0)
Definition: BinUtils.hpp:734
gnsstk::FFBinaryStream::FFBinaryStream
FFBinaryStream()
Default constructor.
Definition: FFBinaryStream.cpp:49
gnsstk::BinUtils::buhtoil
void buhtoil(void *p, uint32_t v, unsigned pos=0)
Definition: BinUtils.hpp:851
gnsstk::BinUtils::buntohf
void buntohf(const void *p, float &v, unsigned pos=0)
Definition: BinUtils.hpp:803
gnsstk::BinUtils::buntohs
void buntohs(const void *p, uint16_t &v, unsigned pos=0)
Definition: BinUtils.hpp:706
gnsstk::BinUtils::buitohl
void buitohl(const void *p, uint32_t &v, unsigned pos=0)
Definition: BinUtils.hpp:587
gnsstk::BinUtils::buitohf
void buitohf(const void *p, float &v, unsigned pos=0)
Definition: BinUtils.hpp:671
gnsstk::BinUtils::buitohd
void buitohd(const void *p, double &v, unsigned pos=0)
Definition: BinUtils.hpp:686
BinUtils.hpp
gnsstk::BinUtils::buhtoill
void buhtoill(void *p, uint64_t v, unsigned pos=0)
Definition: BinUtils.hpp:866
gnsstk::BinUtils::buhtonsll
void buhtonsll(void *p, int64_t v, unsigned pos=0)
Definition: BinUtils.hpp:1047
gnsstk::BinUtils::buhtoisll
void buhtoisll(void *p, int64_t v, unsigned pos=0)
Definition: BinUtils.hpp:915
gnsstk::FFBinaryStream::getData
void getData(uint8_t &v)
Definition: FFBinaryStream.hpp:156
FFBIN_WRITE_DATA
#define FFBIN_WRITE_DATA(HTOI_FN, HTON_FN)
Definition: FFBinaryStream.hpp:147
gnsstk::BinUtils::buntohsl
void buntohsl(const void *p, int32_t &v, unsigned pos=0)
Definition: BinUtils.hpp:767
gnsstk::BinUtils::buhtonf
void buhtonf(void *p, float v, unsigned pos=0)
Definition: BinUtils.hpp:1067
gnsstk::BinUtils::buitohll
void buitohll(const void *p, uint64_t &v, unsigned pos=0)
Definition: BinUtils.hpp:602
example5.fn
string fn
Definition: example5.py:10
FFStream.hpp
gnsstk::BinUtils::buhtoif
void buhtoif(void *p, float v, unsigned pos=0)
Definition: BinUtils.hpp:935
gnsstk::FFBinaryStream::~FFBinaryStream
virtual ~FFBinaryStream()
destructor
Definition: FFBinaryStream.cpp:56
gnsstk::BinUtils::buhtoisl
void buhtoisl(void *p, int32_t v, unsigned pos=0)
Definition: BinUtils.hpp:899
gnsstk::FFBinaryStream::writeData
void writeData(uint8_t v)
Definition: FFBinaryStream.hpp:209
gnsstk::BinUtils::buhtons
void buhtons(void *p, uint16_t v, unsigned pos=0)
Definition: BinUtils.hpp:970
gnsstk::FFBinaryStream::isStreamLittleEndian
virtual bool isStreamLittleEndian() const noexcept=0


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39