GL Studio C++ Runtime API
vpf_table.h
Go to the documentation of this file.
1 /*! \file
2  \brief The VPFTable 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_H
41 #define _VPF_TABLE_H
42 
43 #include "vpf_data_value.h"
44 #include "vpf_table_header.h"
45 #include "vpf_util.h"
46 
47 namespace disti
48 {
49 // forward ref
50 class VPFTableHeader;
51 
52 /** encapsulates a VPF table */
53 class VPFTable
54 {
55 public:
56  /** array of VPFDataValue pointers */
58  /** array of Row pointers */
60 
61  /** Load the VPF table with the given filename es
62  * \param fname filename of VPF table to load
63  * \param abortLoad can be set true by another thread to async abort the load
64  */
65  VPFTable( const char* const fname, volatile bool& abortLoad );
66 
67  /** Load the VPF table with the given filename and ensure that its columns match the columns
68  * described by the given column check structures. Check IsValid() to ensure that table was
69  * loaded successfully and columns match check structures
70  * \param fname filename of VPF table to load
71  * \param columnCheck array of column check structures (!=NULL)
72  * \param numColumnCheck number of check structures in columnCheckArray
73  * \param abortLoad can be set true by another thread to async abort the load
74  */
75  VPFTable( const char* const fname, const VPFTableHeader::ColumnDefinition::Check* const columnCheck,
76  const unsigned int numColumnCheck, volatile bool& abortLoad );
77 
78  /** Dtor
79  */
80  virtual ~VPFTable();
81 
82  /** Get the table header for this table
83  * \return table header for table else NULL
84  */
85  const VPFTableHeader* GetTableHeader( void ) const { return ( _tableHeader ); }
86 
87  /** Get the data in the table
88  * \return table data else NULL
89  */
90  const TableData* GetTableData( void ) const { return ( _data ); }
91 
92  /** Get number of rows in table ( shortcut for GetTableData()->GetRowCount() )
93  * \return number of rows in table
94  */
95  unsigned int GetRowCount( void ) const { return ( _isValid ? _data->GetCount() : 0u ); };
96 
97  /** Get a specific column value from a specific row in the table
98  * \param rowNum zero based row number
99  * \param colNum zero based column number
100  * \return data value from table else NULL
101  */
102  const VPFDataValue* GetTableValue( const unsigned int rowNum, const unsigned int colNum ) const;
103 
104  /** Determine if the table was loaded successfully
105  * \return true if loaded else false
106  */
107  bool IsValid( void ) const { return ( _isValid ); }
108 
109 protected:
110  VPFUtil::WarningBool _isValid; /**< true if a valid table was loaded else false */
111  VPFTableHeader* _tableHeader; /**< header for table else NULL */
112  TableData* _data; /**< rows of table data values else NULL */
113 
114  /** Initialize instance and load table from file. Used by Ctor
115  * \param fname name of file to load
116  * \param abortLoad can be set true by another thread to async abort the load
117  */
118  void Initialize( const char* const fname, volatile bool& abortLoad );
119 
120  /** Read a row of data described by the given table header from the given file
121  * \param infile file to read
122  * \param tableHeader table header describing data to read
123  * \param abortLoad can be set true by another thread to async abort the load
124  * \return new row else NULL
125  */
126  Row* ReadRow( VPFFile& infile, VPFTableHeader& tableHeader, volatile bool& abortLoad ) const;
127 
128  /** Check if a given column definition matches the given column check
129  * \param col zero based column number
130  * \param check column check
131  * \param colCanBeNULL [optional, defaults to false] true if column can optionally be a NULL data type
132  * and pass this check test
133  * \return true if matches else false
134  */
135  bool CheckColumn( const unsigned int col, const VPFTableHeader::ColumnDefinition::Check& check,
136  const bool colCanBeNULL = false ) const;
137 
138  /** Check if a given column definition matches a foreign key definition
139  * \param col zero based column number
140  * \param colName name of column
141  * \param colCanBeNULL [optional, defaults to false] true if column can optionally be a NULL data type
142  * and pass this check test
143  * \return true if matches else false
144  */
145  bool CheckColumnForeignKey( const unsigned int col, const char* const colName, const bool colCanBeNULL = false ) const;
146 
147 private:
148  // Disable implicit generated members
149  VPFTable& operator=( const VPFTable& rhs );
150  VPFTable( const VPFTable& src );
151 };
152 
153 } // end namespace disti
154 
155 #endif // _VPF_TABLE_H
VPFTable(const char *const fname, volatile bool &abortLoad)
unsigned int GetRowCount(void) const
Definition: vpf_table.h:95
unsigned int GetCount(void) const
Definition: vpf_util.h:399
Definition: vpf_table.h:53
VPFUtil::PointerArray< Row > TableData
Definition: vpf_table.h:59
bool IsValid(void) const
Definition: vpf_table.h:107
const VPFTableHeader * GetTableHeader(void) const
Definition: vpf_table.h:85
Util functions for VPF.
bool CheckColumnForeignKey(const unsigned int col, const char *const colName, const bool colCanBeNULL=false) const
TableData * _data
Definition: vpf_table.h:112
The VPFTableHeader class.
VPFUtil::WarningBool _isValid
Definition: vpf_table.h:110
Definition: vpf_table_header.h:51
bool CheckColumn(const unsigned int col, const VPFTableHeader::ColumnDefinition::Check &check, const bool colCanBeNULL=false) const
Definition: vpf_table_header.h:60
Row * ReadRow(VPFFile &infile, VPFTableHeader &tableHeader, volatile bool &abortLoad) const
void Initialize(const char *const fname, volatile bool &abortLoad)
VPFUtil::PointerArray< VPFDataValue > Row
Definition: vpf_table.h:57
Definition: vpf_data_value.h:51
virtual ~VPFTable()
VPFTableHeader * _tableHeader
Definition: vpf_table.h:111
const TableData * GetTableData(void) const
Definition: vpf_table.h:90
Definition: vpf_util.h:272
The VPFDataValue class.
const VPFDataValue * GetTableValue(const unsigned int rowNum, const unsigned int colNum) const
Definition: bmpimage.h:46