GL Studio C++ Runtime API
vpf_table_header.h
Go to the documentation of this file.
1 /*! \file
2  \brief The VPFTableHeader class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef _VPF_TABLE_HEADER_H
41 #define _VPF_TABLE_HEADER_H
42 
43 #include "vpf_util.h"
44 
45 namespace disti
46 {
47 // forward ref
48 class VPFFile;
49 
50 /** reads and encapsulates a VPF table header */
52 {
53 public:
54  /**< VPF table column definition */
56  {
57  public:
58  /** Check structure facilitates ensuring that table header column definitions
59  * match a known spec */
60  struct Check
61  {
62  const char* name; /**< name of column */
63  VPFUtil::DataType dataType; /**< type of data in column */
64  VPFUtil::KeyType keyType; /**< key type for column */
65  int numElements; /**< number of data elements in column (-1 for var length) */
66  };
67 
68  /** Construct a VPF table column definition read from the given file. Input file
69  * should be "seeked" to beginning of column definition and will end "seeked" one past
70  * end of column separator
71  * \param infile input file to read description from
72  */
73  ColumnDefinition( VPFFile& infile );
74 
75  /** Dtor */
77 
78  /** Determine if a valid column definition was read
79  * \return true if valid else false
80  */
81  bool IsValid( void ) const { return ( _isValid ); }
82 
83  /** Get the name of the column
84  * \return name of the column else "" if not valid
85  */
86  const char* GetName( void ) const { return ( _name ); };
87 
88  /** Get the data type of the column
89  * \return data type of the column
90  */
91  VPFUtil::DataType GetDataType( void ) const { return ( _dataType ); }
92 
93  /** Get the number of data elements in the column
94  * \return number of data elements in the column (-1 indicates variable length)
95  */
96  int GetNumberOfElements( void ) const { return ( _numElements ); }
97 
98  /** Get the key type for the column
99  * \return key type for the column
100  */
101  VPFUtil::KeyType GetKeyType( void ) const { return ( _keyType ); }
102 
103  /** Get description of column
104  * \return description of column else NULL if not valid
105  */
106  const char* GetDescription( void ) const { return ( _description ); }
107 
108  /** Get the value description table name of the column
109  * \return value description table name of the column else "" if not valid
110  */
111  const char* GetValueDescriptionTableName( void ) const { return ( _valDescTableName ); }
112 
113  /** Get the thematic indexes name of the column
114  * \return thematic indexes name of the column else "" if not valid
115  */
116  const char* GetThematicIndexName( void ) const { return ( _thematicIndexName ); }
117 
118  /** Get the narrative table name of the column
119  * \return narrative table name of the column else "" if not valid
120  */
121  const char* GetNarrativeTableName( void ) const { return ( _narrativeTableName ); }
122 
123  /** Determine if this column definition matches the given column check
124  * \param colCheck column check
125  * \param colCanBeNULL [optional, defaults to false] true if column can optionally be a NULL data type
126  * and pass this check test
127  * \return true if matches else false
128  */
129  bool CheckDefinition( const Check& colCheck, const bool colCanBeNULL = false ) const;
130 
131  protected:
132  enum
133  {
134  NAME_LENGTH = 17u
135  }; /**< length of name field plus delimiter */
136  enum
137  {
138  VAL_DESC_TABLE_NAME_LENGTH = 13u
139  }; /**< length of value description table name plus delimeter */
140  enum
141  {
142  THEMATIC_INDEXES_NAME_LENGTH = 13u
143  }; /**< length of thematic index name plus delimiter */
144  enum
145  {
146  NARRATIVE_TABLE_NAME_LENGTH = 13u
147  }; /**< length of narrative table name plus delimiter */
148 
149  VPFUtil::WarningBool _isValid; /**< true if a valid definition was read else false */
150  char _name[ NAME_LENGTH + 1u ]; /**< column name plus one for terminator */
151  VPFUtil::DataType _dataType; /**< column data type */
152  int _numElements; /**< number of elements in column else -1 for variable length */
153  VPFUtil::KeyType _keyType; /**< column key type */
154  char* _description; /**< column description (meaning) */
155  char _valDescTableName[ VAL_DESC_TABLE_NAME_LENGTH + 1u ]; /**< value description table name plus one for terminator */
156  char _thematicIndexName[ THEMATIC_INDEXES_NAME_LENGTH + 1u ]; /**< thematic indexes name plus one for terminator */
157  char _narrativeTableName[ NARRATIVE_TABLE_NAME_LENGTH + 1u ]; /**< narrative table name plus one for terminator */
158 
159  /** Read the number of elements and populate _numElements accordingly.
160  * _numElements gets -1 if variable length is indicated. Input file should be
161  * "seeked" to num elements field and will end "seeked" one past column def delimiter
162  * \param infile input file to read number of elements
163  * \return true on success else false
164  */
165  bool ReadNumElements( VPFFile& infile );
166 
167  private:
168  // Disable implicit generated members
169  ColumnDefinition& operator=( const ColumnDefinition& rhs );
170  ColumnDefinition( const ColumnDefinition& src );
171  };
172 
173  /** array of column definition pointers */
175 
176  /** Read the table header from the given VPF file. Infile will be "seeked" to just past
177  * the header on success.
178  * \param infile VPF file to read header from (must be "seeked" to start of file)
179  */
180  VPFTableHeader( VPFFile& infile );
181 
182  /** Get the endian mode read from the table header
183  * \return the endian mode from the table header
184  */
185  VPFUtil::EndianMode GetEndianMode( void ) const { return ( _endianMode ); }
186 
187  /** Get the description from the table header
188  * /return description from the table header
189  */
190  const char* GetDescription( void ) const { return ( _description ); }
191 
192  /** Get the filename of a narrative file associated with the table header
193  * \return narrative filename
194  */
195  const char* GetNarrativeFilename( void ) const { return ( _narrativeFile ); }
196 
197  /** Get the number of columns in the table
198  * \return number of columns in the table
199  */
200  unsigned int GetColumnCount( void ) const { return ( _columnDefs.GetCount() ); }
201 
202  /** Get a column definition for a given column in the table
203  * \param index zero based index into columns
204  * \return column definition at index else NULL
205  */
206  const ColumnDefinition* GetColumnDefinition( unsigned int index ) const
207  {
208  return ( _columnDefs.GetPointer( index ) );
209  }
210 
211  /** Find the column index to the column in the table header with the given column name
212  * \param colName name of desired column
213  * \param colIndex [out] receives zero based column index on success
214  * \return true if column found else false
215  */
216  bool FindColumn( const char* const colName, unsigned int& colIndex ) const;
217 
218  /** \return True if the header was read successfully from the file */
219  bool IsValid( void ) const { return ( _isValid ); }
220 
221 protected:
222  enum
223  {
224  DESCRIPTION_LENGTH = 81u
225  }; /**< length of description field plus delimiter */
226  enum
227  {
228  NARRATIVE_FILE_LENGTH = 13u
229  }; /**< length of narrative filename plus delimiter */
230 
231  VPFUtil::WarningBool _isValid; /**< true if header was read successfully else false */
232  VPFUtil::EndianMode _endianMode; /**< endian mode of data in table */
233  char _description[ DESCRIPTION_LENGTH + 1u ]; /**< table description plus terminator */
234  char _narrativeFile[ NARRATIVE_FILE_LENGTH + 1u ]; /**< narrative file name plus terminator */
235  ColumnDefinitionArray _columnDefs; /**< column definitions in header */
236 
237 private:
238  // Disable implicit generated members
239  VPFTableHeader& operator=( const VPFTableHeader& rhs );
240  VPFTableHeader( const VPFTableHeader& src );
241 };
242 
243 } // end namespace disti
244 
245 #endif // _VPF_TABLE_HEADER_H
Definition: vpf_table_header.h:55
VPFUtil::WarningBool _isValid
Definition: vpf_table_header.h:231
unsigned int GetCount(void) const
Definition: vpf_util.h:399
bool IsValid(void) const
Definition: vpf_table_header.h:81
Util functions for VPF.
T * GetPointer(const unsigned int index)
Definition: vpf_util.h:405
const char * GetDescription(void) const
Definition: vpf_table_header.h:106
bool FindColumn(const char *const colName, unsigned int &colIndex) const
char _thematicIndexName[THEMATIC_INDEXES_NAME_LENGTH+1u]
Definition: vpf_table_header.h:156
const char * GetName(void) const
Definition: vpf_table_header.h:86
const char * GetDescription(void) const
Definition: vpf_table_header.h:190
VPFUtil::EndianMode GetEndianMode(void) const
Definition: vpf_table_header.h:185
char _narrativeFile[NARRATIVE_FILE_LENGTH+1u]
Definition: vpf_table_header.h:234
VPFUtil::EndianMode _endianMode
Definition: vpf_table_header.h:232
const char * GetThematicIndexName(void) const
Definition: vpf_table_header.h:116
Definition: vpf_table_header.h:51
VPFUtil::DataType GetDataType(void) const
Definition: vpf_table_header.h:91
VPFTableHeader(VPFFile &infile)
char _name[NAME_LENGTH+1u]
Definition: vpf_table_header.h:150
Definition: vpf_table_header.h:60
int _numElements
Definition: vpf_table_header.h:152
KeyType
Definition: vpf_util.h:165
unsigned int GetColumnCount(void) const
Definition: vpf_table_header.h:200
char _narrativeTableName[NARRATIVE_TABLE_NAME_LENGTH+1u]
Definition: vpf_table_header.h:157
VPFUtil::PointerArray< ColumnDefinition > ColumnDefinitionArray
Definition: vpf_table_header.h:174
ColumnDefinitionArray _columnDefs
Definition: vpf_table_header.h:235
DataType
Definition: vpf_util.h:145
char _description[DESCRIPTION_LENGTH+1u]
Definition: vpf_table_header.h:233
const ColumnDefinition * GetColumnDefinition(unsigned int index) const
Definition: vpf_table_header.h:206
VPFUtil::KeyType keyType
Definition: vpf_table_header.h:64
int numElements
Definition: vpf_table_header.h:65
const char * GetNarrativeFilename(void) const
Definition: vpf_table_header.h:195
bool CheckDefinition(const Check &colCheck, const bool colCanBeNULL=false) const
VPFUtil::KeyType _keyType
Definition: vpf_table_header.h:153
const char * GetValueDescriptionTableName(void) const
Definition: vpf_table_header.h:111
VPFUtil::WarningBool _isValid
Definition: vpf_table_header.h:149
int GetNumberOfElements(void) const
Definition: vpf_table_header.h:96
const char * GetNarrativeTableName(void) const
Definition: vpf_table_header.h:121
char * _description
Definition: vpf_table_header.h:154
bool IsValid(void) const
Definition: vpf_table_header.h:219
char _valDescTableName[VAL_DESC_TABLE_NAME_LENGTH+1u]
Definition: vpf_table_header.h:155
VPFUtil::DataType _dataType
Definition: vpf_table_header.h:151
EndianMode
Definition: vpf_util.h:138
VPFUtil::KeyType GetKeyType(void) const
Definition: vpf_table_header.h:101
const char * name
Definition: vpf_table_header.h:62
Definition: bmpimage.h:46
VPFUtil::DataType dataType
Definition: vpf_table_header.h:63