ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
rtkDbf.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright RTK Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19#ifndef rtkDbf_h
20#define rtkDbf_h
21
22#include "RTKExport.h"
23#include "itkWin32Header.h"
24#include <cstdlib>
25#include <fstream>
26#include <map>
27#include <string>
28#include <vector>
29
30namespace rtk
31{
32
41class RTK_EXPORT DbfField
42{
43public:
45 DbfField(std::string name, char type, unsigned char length, short recOffset);
46
48 std::string
50 {
51 return m_Name;
52 }
53 [[nodiscard]] char
54 GetType() const
55 {
56 return m_Type;
57 }
58 [[nodiscard]] short
59 GetLength() const
60 {
61 return m_Length;
62 }
63
65 [[nodiscard]] short
67 {
68 return m_RecOffset;
69 }
70
71private:
72 std::string m_Name;
73 char m_Type;
74 short m_Length;
76};
77
88class RTK_EXPORT DbfFile
89{
90public:
92 explicit DbfFile(const std::string & fileName);
94
96 bool
98 {
99 return m_Stream.is_open();
100 }
101
103 size_t
105 {
106 return m_Fields.size();
107 }
108
111 bool
113
115 std::string
116 GetFieldAsString(const std::string & fldName);
117
118 double
119 GetFieldAsDouble(const std::string & fldName)
120 {
121 return std::stod(GetFieldAsString(fldName));
122 }
123
124private:
126 std::ifstream m_Stream;
127
129 unsigned int m_NumRecords{};
130 unsigned short m_RecordSize{};
131 unsigned short m_HeaderSize{};
132
134 std::vector<DbfField> m_Fields;
135
137 std::map<std::string, unsigned int> m_MapFieldNameIndex;
138
140 char * m_Record;
141};
142} // namespace rtk
143
144#endif
std::string GetName()
Definition rtkDbf.h:49
char GetType() const
Definition rtkDbf.h:54
char m_Type
Definition rtkDbf.h:73
DbfField(std::string name, char type, unsigned char length, short recOffset)
short GetLength() const
Definition rtkDbf.h:59
short GetRecOffset() const
Definition rtkDbf.h:66
std::string m_Name
Definition rtkDbf.h:72
short m_RecOffset
Definition rtkDbf.h:75
short m_Length
Definition rtkDbf.h:74
std::ifstream m_Stream
Definition rtkDbf.h:126
std::map< std::string, unsigned int > m_MapFieldNameIndex
Definition rtkDbf.h:137
std::string GetFieldAsString(const std::string &fldName)
vcl_size_t GetNumberOfRecords()
Definition rtkDbf.h:104
unsigned short m_HeaderSize
Definition rtkDbf.h:131
unsigned int m_NumRecords
Definition rtkDbf.h:129
unsigned short m_RecordSize
Definition rtkDbf.h:130
bool ReadNextRecord()
char * m_Record
Definition rtkDbf.h:140
bool is_open()
Definition rtkDbf.h:97
std::vector< DbfField > m_Fields
Definition rtkDbf.h:134
double GetFieldAsDouble(const std::string &fldName)
Definition rtkDbf.h:119
DbfFile(const std::string &fileName)