Software and Services, Portable Libraries  2019.Mar.01
A library for managing digital certificates
Base.hpp
Go to the documentation of this file.
1 //
2 // BEGIN_SOFTWARE_AND_SERVICES_COPYRIGHT
3 //
4 // Copyright (C) 2010-2012 Software and Services LLC, All Rights Reserved.
5 //
6 // NOTICE:
7 //
8 // THIS SOURCE CODE BELONGS TO Software and Services LLC.
9 // THIS CODE IS PROPERTY OF THE COPYRIGHT HOLDER AND IS NOT TO
10 // BE DIVULGED OR USED BY PARTIES WHO HAVE NOT RECEIVED WRITTEN
11 // AUTHORIZATION FROM THE OWNER.
12 //
13 // THIS SOFTWARE AND MANUAL ARE BOTH PROTECTED BY UNITED STATES
14 // COPYRIGHT LAW (TITLE 17 UNITED STATES CODE). UNAUTHORIZED REPRODUCTION
15 // AND/OR SALE MAY RESULT IN IMPRISONMENT OF UP TO ONE YEAR AND FINES
16 // OF UP TO $100,000 (17 USC 506). COPYRIGHT INFRINGERS MAY ALSO
17 // BE SUBJECT TO CIVIL LIABILITY.
18 //
19 // THIS NOTICE AND THE ABOVE COPYRIGHT NOTICE MUST REMAIN IN ALL
20 // COPIES AND ANY DERIVED WORK.
21 //
22 // ALL OF THIS CODE IS ORIGINAL WORK BY THE COPYRIGHT HOLDER.
23 //
24 // THIS DOCUMENT AND THE INFORMATION CONTAINED HEREIN IS
25 // PROVIDED ON AN "AS IS" BASIS AND Software and Services LLC.
26 // DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
27 // NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
28 // HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
29 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
30 // PURPOSE.
31 //
32 // END_SOFTWARE_AND_SERVICES_COPYRIGHT
33 //
34 
49 #ifndef SOFTWARE_AND_SERVICES_LIBRARY_COMMON_BASE_HPP_
50 #define SOFTWARE_AND_SERVICES_LIBRARY_COMMON_BASE_HPP_
51 
52 #ifdef WIN32
53 #pragma warning (disable : 4251)
54 #endif
55 
56 
57 #include <sys/types.h>
58 
59 #ifdef BUILDING_SAS_COMMON_LIBRARY
60 #include "osver.h"
61 #include "File.hpp"
62 #include "VBase.hpp"
63 #include "instance.hpp"
64 #else
65 #include <SaS/Common/osver.h>
66 #include <SaS/Common/File.hpp>
67 #include <SaS/Common/VBase.hpp>
68 #include <SaS/Common/instance.hpp>
69 #endif
70 
71 #ifdef MINGW
72 #include <mingw.hpp>
73 #endif
74 
75 #ifndef EXPORT_COMMON
76 #ifdef BUILDING_SAS_COMMON_LIBRARY
77 #define EXPORT_COMMON EXPORT_OUT
78 #else
79 #define EXPORT_COMMON EXPORT_IN
80 #endif
81 #endif
82 
83 #ifdef WIN32
84 #define htonll(u64) _byteswap_uint64(u64)
85 #define ntohll(u64) _byteswap_uint64(u64)
86 #undef HAVE_HTONLL
87 #else
88 
89 #ifdef Linux
90 #include <stdint.h>
91 #undef HAVE_HTONLL
92 #endif // Linux
93 uint64_t htonll(uint64_t host64);
94 uint64_t ntohll(uint64_t host64);
95 
96 #endif // WIN32
97 
99 {
100  namespace Library
101  {
102  namespace Common
103  {
104 
125  class EXPORT_COMMON Base
126  : public File
127  {
128 
129  public:
130 
131 
132 #ifdef FILE_USE_STD
133 
140  Base(std::fstream * fs, const char * aFileName);
141 #endif
142 
149  Base(const int fd, const char * aFileName);
150 
151 
157  explicit Base(const char * buffer);
158 
164  explicit Base(const wchar_t * buffer);
165 
171  Base(File * file = nullptr);
172 
176  virtual ~Base();
177 
191  bool open(const char * file, int RWmode);
192 
200  bool close();
201 
211  void operator delete(void * data);
212 
217  enum open_flags {
218 
220  O_CREAT_t = O_CREAT,
221 
223  O_RDONLY_t = O_RDONLY,
224 
226  O_WRONLY_t = O_WRONLY
227 
228  //
229  };
230 
234  enum endian_t {
235  BigEndian_t = 4321, // SPARC
236  LittleEndian_t = 1234, // INTEL
237  NetworkByteOrder_t = BigEndian_t,
238  UnknownEndian_t = 0
239  };
240 
248  void DoIoInNetworkByteOrder(bool NetOrder);
249 
255  bool WeAreNetworkByteOrder();
256 
262  bool writeEndian(endian_t Value);
263 
269  bool readEndian(endian_t * Value);
270 
276  bool writeBool(bool Value);
277 
283  bool readBool(bool * Value);
284 
290  bool writeChar(char Value);
291 
299  bool readChar(char * Value);
300 
306  bool writeUChar(unsigned char Value);
307 
315  bool readUChar(unsigned char * Value);
316 
322  bool writeShort(short Value);
323 
329  bool readShort(short * Value);
330 
336  bool writeUShort(unsigned short Value);
337 
343  bool readUShort(unsigned short * Value);
344 
350  bool writeInt(int Value);
351 
357  bool readInt(int * Value);
358 
364  bool writeUInt(unsigned int Value);
365 
371  bool readUInt(unsigned int * Value);
372 
378  bool writeLong(long Value);
379 
385  bool readLong(long * Value);
386 
392  bool writeULong(unsigned long Value);
393 
399  bool readULong(unsigned long * Value);
400 
406  bool readLongLong(long long * Value);
407 
413  bool writeLongLong(long long Value);
414 
420  bool readULongLong(unsigned long long * Value);
421 
427  bool writeULongLong(unsigned long long Value);
428 
434  bool readFloat(float * Value);
435 
441  bool writeFloat(float Value);
442 
448  bool readDouble(double * Value);
449 
455  bool writeDouble(double Value);
456 
462  bool writeString(const char * Value);
463 
469  bool readString(char ** Value);
470 
476  bool writeToken(const Token_t token);
477 
483  bool readToken(Token_t * token);
484 
485  private:
486 
490  bool _DoIoInNetworkByteOrder;
491 
495  endian_t _OurByteOrder;
496 
500  endian_t _GetOurByteOrder();
501 
505  File * _File;
506 
510  bool _WeOpenedFile;
511  };
512  }
513  }
514 }
515 #endif /*SOFTWARE_AND_SERVICES_LIBRARY_COMMON_BASE_HPP_*/
endian_t
enumerated types for BIG_ENDIAN and LITTLE_ENDIAN.
Definition: Base.hpp:234
Like &#39;FILE&#39;, except C++ implementation and allows sockets and disk files to use same object on WINDOW...
Definition: File.hpp:150
Generic buffered IO.
A portable I/O library for reading and writing binary data.
Definition: Base.hpp:125
"<SaS/Common/mingw.hpp>" Definitions when compiling with MINGW.
Copyright Douglas Mark Royer DouglasRoyer@gmail.com.
Definition: Base.hpp:98
Base class for instance counting objects.
Base virtual functions for IO.
"<SaS/Common/psver.h>" Definitions specific to various OS&#39;s and OS versions.