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{
26
27#pragma pack(push)
28#pragma pack(1)
43#pragma pack(pop)
44
46 {
47 public:
48 DBFParser(const File& file);
49
50 void DumpAll(const char* szDestFileName);
51 void DumpFields(const char* szDestFileName, const char** fields, size_t numFields);
52 size_t recordCount() const { return stHeader.uNumRecords; }
53 template<class t_type>
55 {
57 uint04 row_skip_size = 0;
58 uint04 final_offset = 0;
59 for (uint04 i = 0; i < columns.size(); ++i)
60 {
61 if (columns[i].archName == column)
62 {
63 index = i;
64 final_offset = szRowSize - (row_skip_size + columns[i].uLength);
65 break;
66 }
67 row_skip_size += columns[i].uLength;
68 }
69 Buffer<t_type> buff;
70 if (isNaN(index))
71 return buff;
72 clFile.seekg(m_data_start, std::ios_base::beg);
73 buff.ensureCapacity(stHeader.uNumRecords);
74 size_t uNumRecords = 0;
75 String s;
76 while (uNumRecords < stHeader.uNumRecords)
77 {
78 char deleted;
79 clFile.read(&deleted, 1);
80 if (deleted == 0x2A)
81 {
82 clFile.seekg(szRowSize, std::ios_base::cur);
83 continue;
84 }
85
86 if (row_skip_size > 0)
87 {
88 clFile.seekg(row_skip_size, std::ios_base::cur);
89 }
90 ///
91 s.setSize(columns[index].uLength);
92 clFile.read(s.begin(), columns[index].uLength);
93 buff.add(s.trimWhiteSpace().getAs<t_type>());
94
95 ///
96 if (final_offset > 0)
97 clFile.seekg(final_offset, std::ios_base::cur);
98
99 ++uNumRecords;
100 }
101 return buff;
102 }
103
104 private:
105 std::ifstream clFile;
106
107 DbfHeader_s stHeader;
108 Buffer<DbfRecord_s> columns;
109 size_t m_data_start;
110 size_t szRowSize;
111 size_t szLargestFieldSize;
112 };
113}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
void ensureCapacity(t_index_type new_capacity, bool ensure_not_greater=false, bool ensure_not_less=true)
Definition Buffer.hpp:803
decltype(auto) begin()
Definition Buffer.hpp:504
Definition DBFParser.h:46
size_t recordCount() const
Definition DBFParser.h:52
Buffer< t_type > readColumn(const String &column)
Definition DBFParser.h:54
Definition File.h:47
Definition String.h:40
NDEVR_BASE_API String & trimWhiteSpace()
Definition String.cpp:569
t_type getAs() const
Definition String.h:334
Definition ACIColor.h:37
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:109
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
Definition BaseValues.hpp:272
Definition DBFParser.h:11
uint02 uRecordSize
Definition DBFParser.h:18
uint02 uFirstRecordOffset
Definition DBFParser.h:17
char uReserved[15]
Definition DBFParser.h:20
uint01 fFlags
Definition DBFParser.h:21
uint04 uNumRecords
Definition DBFParser.h:15
uint8_t iType
Definition DBFParser.h:12
uint01 uCodePageMark
Definition DBFParser.h:22
char arcLastUpdate[3]
Definition DBFParser.h:13
char uReserved2[2]
Definition DBFParser.h:24
Definition DBFParser.h:30
char chFieldType
Definition DBFParser.h:32
uint01 fFlags
Definition DBFParser.h:37
uint01 uDecimalPlaces
Definition DBFParser.h:36
char archName[11]
Definition DBFParser.h:31
uint01 uStepValue
Definition DBFParser.h:40
uint04 uNextValue
Definition DBFParser.h:39
uint01 uLength
Definition DBFParser.h:35
uint04 uDisplacement
Definition DBFParser.h:34
char uReserved[8]
Definition DBFParser.h:41