OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
VcstLutInputItem.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * NAME: VcstLutInputItem.h
4  *
5  * DESCRIPTION: Base class for all Geolocation and Calibration LUT Input Item
6  * object classes. Provides basic functionality to read binary files and manage
7  * data associated with characteristics of the files.
8  *
9  * Based on various IDPS object classes published by Raytheon Company that support
10  * similar functionality.
11  *
12  *******************************************************************************/
13 
14 #ifndef VcstLutInputItem_h
15 #define VcstLutInputItem_h
16 
17 #include <string>
18 
20 public:
21 
28  VcstLutInputItem(const std::string& groupName, size_t size);
29 
34  virtual ~VcstLutInputItem();
35 
40  static VcstLutInputItem* getInstance() {
41  return new VcstLutInputItem;
42  }
43 
50  virtual int getData();
51 
52  inline void* getDataPtr() const {
53  return dataPtr_;
54  }
55 
56  inline bool dataPtrUnknown() const {
57  return !dataPtrEstablished();
58  }
59 
60  const std::string getShortName() const;
61 
62  void setShortName(const std::string& shortName);
63 
64  const std::string getFilePath() const;
65 
66  void setFilePath(const std::string& filePath);
67 
68  const std::string getFileName() const;
69 
70  inline void setDataPtr(void* ptr) {
71  dataPtr_ = ptr;
72  }
73 
74 protected:
75 
76  static const std::size_t MAX_IO_SIZE = 1073741824;
77 
83  virtual bool isItemOkForIO();
84 
89  inline const std::string getGroupName() const {
90  return groupName_;
91  }
92 
93  inline const size_t getDataSize() const {
94  return dataSize_;
95  }
96 
97  inline const bool dataPtrEstablished() const {
98  return (dataPtr_ != 0);
99  }
100 
105  inline void setGroupName(std::string strName) {
106  groupName_ = strName;
107  }
108 
109  inline void setDataSize(size_t size) {
110  dataSize_ = size;
111  }
112 
113  inline void setIsAllocated(bool bVal) {
114  isAllocated_ = bVal;
115  }
116 
121  size_t determineFileSize(const std::string& fileName);
122 
127  int allocateMemory(size_t size);
128 
133  void releaseMemory();
134 
139  virtual int convertEndianness();
140 
147  template<typename T>
148  static void byteSwap(T& aValue);
149 
155 
156 private:
157 
163 
169 
174  VcstLutInputItem& operator=(const VcstLutInputItem& right);
175 
180  int readMetadata(std::string filepath);
181 
186  void* dataPtr_;
187 
192  size_t dataSize_;
193 
198  bool isAllocated_;
199 
204  bool bLittleEndian_;
205 
210  std::string shortName_;
211 
216  std::string filePath_;
217 
218 };
219 
220 //---------------------------------------------------------------------------
221 // Converts the endianness of the parameter by performing the appropriate
222 // byte swapping.
223 //---------------------------------------------------------------------------
224 
225 template<typename T>
226 void VcstLutInputItem::byteSwap(T& aValue) {
227  T tempValue = aValue; // a temporary copy of the value
228 
229  // Pointers to the first byte of both variables
230  unsigned char* aValuePtr = reinterpret_cast<unsigned char*> (&aValue);
231  unsigned char* tempValuePtr = reinterpret_cast<unsigned char*> (&tempValue);
232 
233  // Swap the byte order
234  for (unsigned int byte = 0; byte < sizeof (aValue); ++byte) {
235  aValuePtr[byte] = tempValuePtr[(sizeof (aValue) - 1) - byte];
236  }
237 }
238 
239 #endif
const size_t getDataSize() const
void setShortName(const std::string &shortName)
static VcstLutInputItem * getInstance()
const bool dataPtrEstablished() const
const std::string getFilePath() const
const std::string getFileName() const
void setFilePath(const std::string &filePath)
void * getDataPtr() const
@ string
void setDataSize(size_t size)
const std::string getGroupName() const
virtual int convertEndianness()
static const std::size_t MAX_IO_SIZE
void setGroupName(std::string strName)
static void byteSwap(T &aValue)
const std::string getShortName() const
size_t determineFileSize(const std::string &fileName)
int allocateMemory(size_t size)
virtual ~VcstLutInputItem()
string filepath
Definition: color_dtdb.py:207
virtual bool isItemOkForIO()
void setIsAllocated(bool bVal)
std::string groupName_
virtual int getData()
void setDataPtr(void *ptr)
bool dataPtrUnknown() const
#define byte
Definition: input_s.h:5