📄 binexdata.hpp
字号:
#pragma ident "$Id: //depot/msn/main/code/shared/gpstk/BinexData.hpp#1 $"/** * @file BinexData.hpp * Encapsulate BINEX file data, including I/O */#ifndef GPSTK_BINEXDATA_HPP#define GPSTK_BINEXDATA_HPP#include "gpstkplatform.h"#include "BinUtils.hpp"#include "FFData.hpp"#include "FFStream.hpp"namespace gpstk{ /** @addtogroup Binex */ //@{ /** * This class stores, reads, and writes BINEX records. * * @sa binex_read_write.cpp for an example. * @sa binex_test.cpp for an example. * @sa BinexStream. */ class BinexData : public FFData { public: // Establish the endianness of the native platform #if BYTE_ORDER == LITTLE_ENDIAN static const bool nativeLittleEndian = true; #else static const bool nativeLittleEndian = false; #endif static const unsigned long INVALID_RECORD_ID = 0xFFFFFFFF; static const unsigned char DEFAULT_RECORD_FLAGS = 0x20; static const unsigned char VALID_RECORD_FLAGS = 0x38; // Flags indicating whether a record is reversed, whether a record // is big endian, and whether a record contains an enhanced CRC. // Combining these flags (via bitwise-or) helps create the // synchronization byte(s) for a BINEX record. enum recordFlagsEnum { eReverseReadable = 0x10, eBigEndian = 0x20, eEnhancedCRC = 0x08 }; /// BINEX data types //@{ /** * An unsigned integer stored using 1, 2, 3, or 4 bytes to represent * integers from 0 to 536870911; used to represent BINEX record IDs, * subrecord IDs, field IDs, and so on. */ class UBNXI { public: static const unsigned long MIN_VALUE = 0; static const unsigned long MAX_VALUE = 536870911; static const unsigned char MAX_BYTES = 4; /** * Default constructor - sets value to 0. */ UBNXI(); /** * Copy constructor. */ UBNXI(const UBNXI& other) { *this = other; }; /** * Constructor with unsigned long initialization value. */ UBNXI(unsigned long ul) throw(FFStreamError); /** * Copies another UBNXI. */ inline UBNXI& operator=(const UBNXI& right) { value = right.value; size = right.size; return *this; }; /** * Compares two UBNXI's for equality. */ inline bool operator==(const UBNXI& other) const { return (value == other.value); }; /** * Compares two UBNXI's for inequality. */ inline bool operator!=(const UBNXI& other) const { return (value != other.value); }; /** * Returns whether this UBNXI is less than the other. */ inline bool operator<(const UBNXI& other) const { return (value < other.value); }; /** * Returns whether this UBNXI is less than or equal to the other. */ inline bool operator<=(const UBNXI& other) const { return (value <= other.value); }; /** * Returns whether this UBNXI is greater than the other. */ inline bool operator>(const UBNXI& other) const { return (value > other.value); }; /** * Returns whether this UBNXI is greater than or equal to the other. */ inline bool operator>=(const UBNXI& other) const { return (value >= other.value); }; /** * Returns the value of the UBNXI as an unsigned long. */ inline operator unsigned long() const { return value; }; /** * Returns the number of bytes required to represent the UBNXI. * A size of 0 indicates an invalid or uninitialized UBNXI. */ inline size_t getSize() const { return size; }; /** * Attempts to decode a valid UBNXI from the contents of inBuffer. * The contents of inBuffer are assumed to be in normal order * (i.e. not reversed) but may be either big or little endian. * @param inBuffer Sequence of bytes to decode * @param offset Offset into inBuffer at which to decode * @param littleEndian Byte order of the encoded bytes * @return Number of bytes decoded */ size_t decode(const std::string& inBuffer, size_t offset = 0, bool littleEndian = false) throw(FFStreamError); /** * Converts the UBNXI to a series of bytes placed in outBuffer. * The bytes are output in normal order (i.e. not reversed) but * may encode in either big or little endian format. * @param outBuffer Sequence of encoded bytes * @param offset Offset into outBuffer at which to encode * @param littleEndian Optional flag indicating byte order of * the encoded bytes * @return Number of bytes used to encode */ size_t encode(std::string& outBuffer, size_t offset = 0, bool littleEndian = false) const; /** * Attempts to read a valid UBNXI from the specified input stream. * The stream can be in reverse order and can be * big or little endian. If the method succeeds, the number * of bytes used to contruct the UBNXI can be determined * by calling the getSize() method. * @param strm Stream from which to read * @param outBuffer Optional buffer to receive copy of raw input * @param offset Offset into outBuffer at which to copy input * @param reverseBytes Optional flag indicating whether * the input bytes are reversed * @param littleEndian Optional flag indicating byte order of input * @return Number of bytes removed from the input stream */ size_t read(std::istream& strm, std::string *outBuffer = NULL, size_t offset = 0, bool reverseBytes = false, bool littleEndian = false) throw(FFStreamError); /** * Attempts to write the UBNXI to the specified output stream. * The stream can be output in reverse order and can be * big or little endian. The method fails if the entire * UBNXI cannot be written to the stream. * @param strm Stream in which to write * @param outBuffer Optional buffer to receive copy of raw ouput * @param offset Offset into outBuffer at which to copy output * @param reverseBytes Optional flag indicating whether * the ouput bytes should be reversed * @param littleEndian Optional flag indicating byte order of output * @return Number of bytes added to the output stream */ size_t write(std::ostream& strm, std::string *outBuffer = NULL, size_t offset = 0, bool reverseBytes = false, bool littleEndian = false) const throw(FFStreamError); protected: unsigned long value; size_t size; }; /** * A signed integer stored using 1, 2, 3, 4, 5, 6, 7, or 8 bytes to * represent integers from about -1.15292e18 to +1.15292e18 using a * modified version of a compression scheme developed by GFZ, plus * using "special" numbers to flag certain conditions, such as using * the 1-byte MFGZI to store "-0" to indicate "no value." */ class MGFZI { public: static const long long MIN_VALUE = -1157442765409226759LL; static const long long MAX_VALUE = 1157442765409226759LL; static const unsigned char MAX_BYTES = 8; /** * Default constructor - sets value to 0. */ MGFZI(); /** * Copy constructor. */ MGFZI(const MGFZI& other) { *this = other; }; /** * Constructor with a long long initialization value. */ MGFZI(long long ll) throw(FFStreamError); /** * Copies another MGFZI. */ inline MGFZI& operator=(const MGFZI& right) { value = right.value; size = right.size; return *this; }; /** * Compares two MGFZI's for equality. */ inline bool operator==(const MGFZI& other) const { return (value == other.value); }; /** * Compares two MGFZI's for inequality. */ inline bool
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -