RTK  2.6.0
Reconstruction Toolkit
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 <string>
25 #include <fstream>
26 #include <vector>
27 #include <map>
28 #include <cstdlib>
29 
30 namespace rtk
31 {
32 
41 class RTK_EXPORT DbfField
42 {
43 public:
45  DbfField(std::string name, char type, unsigned char length, short recOffset);
46 
48  std::string
50  {
51  return m_Name;
52  }
53  char
54  GetType() const
55  {
56  return m_Type;
57  }
58  short
59  GetLength() const
60  {
61  return m_Length;
62  }
64 
66  short
67  GetRecOffset() const
68  {
69  return m_RecOffset;
70  }
71 
72 private:
73  std::string m_Name;
74  char m_Type;
75  short m_Length;
76  short m_RecOffset;
77 };
78 
89 class RTK_EXPORT DbfFile
90 {
91 public:
93  DbfFile(std::string fileName);
94  ~DbfFile();
96 
98  bool
100  {
101  return m_Stream.is_open();
102  }
103 
105  size_t
107  {
108  return m_Fields.size();
109  }
110 
113  bool
114  ReadNextRecord();
115 
117  std::string
118  GetFieldAsString(std::string fldName);
119 
120  double
121  GetFieldAsDouble(std::string fldName)
122  {
123  return std::stod(GetFieldAsString(fldName).c_str());
124  }
125 
126 private:
128  std::ifstream m_Stream;
129 
131  unsigned int m_NumRecords;
132  unsigned short m_RecordSize;
133  unsigned short m_HeaderSize;
134 
136  std::vector<DbfField> m_Fields;
137 
139  std::map<std::string, unsigned int> m_MapFieldNameIndex;
140 
142  char * m_Record;
143 };
144 } // namespace rtk
145 
146 #endif
vcl_size_t GetNumberOfRecords()
Definition: rtkDbf.h:106
short m_RecOffset
Definition: rtkDbf.h:76
char m_Type
Definition: rtkDbf.h:74
char GetType() const
Definition: rtkDbf.h:54
double GetFieldAsDouble(std::string fldName)
Definition: rtkDbf.h:121
short GetRecOffset() const
Definition: rtkDbf.h:67
short GetLength() const
Definition: rtkDbf.h:59
unsigned int m_NumRecords
Definition: rtkDbf.h:131
std::map< std::string, unsigned int > m_MapFieldNameIndex
Definition: rtkDbf.h:139
unsigned short m_RecordSize
Definition: rtkDbf.h:132
std::ifstream m_Stream
Definition: rtkDbf.h:128
std::string GetName()
Definition: rtkDbf.h:49
std::vector< DbfField > m_Fields
Definition: rtkDbf.h:136
bool is_open()
Definition: rtkDbf.h:99
std::string m_Name
Definition: rtkDbf.h:73
unsigned short m_HeaderSize
Definition: rtkDbf.h:133
char * m_Record
Definition: rtkDbf.h:142
short m_Length
Definition: rtkDbf.h:75