API Documentation
Loading...
Searching...
No Matches
DBFParser.h
Go to the documentation of this file.
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/BaseValues.h>
4#include <NDEVR/File.h>
5#include <NDEVR/Buffer.h>
6#include <fstream>
7#include <vector>
8namespace NDEVR
9{
10 /**----------------------------------------------------------------------------
11 \brief Logic for reading or writing to a database file that uses the .dbf
12 file extension
13 ----------------------------------------------------------------------------*/
15 {
16 public:
17 DBFParser(const File& file);
18 void DumpAll(const char* szDestFileName);
19 void DumpFields(const char* szDestFileName, const char** fields, size_t numFields);
20 size_t recordCount() const { return stHeader.uNumRecords; }
21 template<class t_type>
23 {
25 uint04 row_skip_size = 0;
26 uint04 final_offset = 0;
27 for (uint04 i = 0; i < columns.size(); ++i)
28 {
29 if (columns[i].archName == column)
30 {
31 index = i;
32 final_offset = szRowSize - (row_skip_size + columns[i].uLength);
33 break;
34 }
35 row_skip_size += columns[i].uLength;
36 }
37 Buffer<t_type> buff;
38 if (IsInvalid(index))
39 return buff;
40 clFile.seekg(m_data_start, std::ios_base::beg);
41 buff.ensureCapacity(stHeader.uNumRecords);
42 size_t uNumRecords = 0;
43 String s;
44 while (uNumRecords < stHeader.uNumRecords)
45 {
46 char deleted;
47 clFile.read(&deleted, 1);
48 if (deleted == 0x2A)
49 {
50 clFile.seekg(szRowSize, std::ios_base::cur);
51 continue;
52 }
53
54 if (row_skip_size > 0)
55 {
56 clFile.seekg(row_skip_size, std::ios_base::cur);
57 }
58 ///
59 s.setSize(columns[index].uLength);
60 clFile.read(s.begin(), columns[index].uLength);
61 buff.add(s.trimWhiteSpace().getAs<t_type>());
62
63 ///
64 if (final_offset > 0)
65 clFile.seekg(final_offset, std::ios_base::cur);
66
67 ++uNumRecords;
68 }
69 return buff;
70 }
71
72 private:
73 struct DbfHeader_s
74 {
75 uint8_t iType;
76 char arcLastUpdate[3];
77
78 uint04 uNumRecords;
79
80 uint02 uFirstRecordOffset;
81 uint02 uRecordSize;
82
83 char uReserved[15];
84 uint01 fFlags;
85 uint01 uCodePageMark;
86
87 char uReserved2[2];
88 };
89
90#pragma pack(push)
91#pragma pack(1)
92 struct DbfRecord_s
93 {
94 char archName[11];
95 char chFieldType;
96
97 uint04 uDisplacement;
98 uint01 uLength;
99 uint01 uDecimalPlaces;
100 uint01 fFlags;
101
102 uint04 uNextValue;
103 uint01 uStepValue;
104 char uReserved[8];
105 };
106 struct FieldInfo_s
107 {
108 const DbfRecord_s& rstRecord;
109 size_t szSkipSize;
110
111 FieldInfo_s(const DbfRecord_s& rec) :
112 rstRecord(rec),
113 szSkipSize(0)
114 {
115 }
116 };
117#pragma pack(pop)
118 std::ifstream clFile;
119 DbfHeader_s stHeader;
120 Buffer<DbfRecord_s> columns;
121 size_t m_data_start;
122 size_t szRowSize;
123 size_t szLargestFieldSize;
124 };
125}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:186
void setSize(t_index_type new_size)
Definition Buffer.hpp:803
void ensureCapacity(t_index_type new_capacity, bool ensure_not_greater=false, bool ensure_not_less=true)
Definition Buffer.hpp:519
decltype(auto) begin()
Definition Buffer.hpp:402
Logic for reading or writing to a database file that uses the .dbf.
Definition DBFParser.h:15
void DumpFields(const char *szDestFileName, const char **fields, size_t numFields)
size_t recordCount() const
Definition DBFParser.h:20
void DumpAll(const char *szDestFileName)
DBFParser(const File &file)
Buffer< t_type > readColumn(const String &column)
Definition DBFParser.h:22
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
The core String class for the NDEVR API.
Definition String.h:69
String & trimWhiteSpace()
Trims any white space (tabs, spaces, etc) from the beginning and end of the string.
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:88
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233