RTK  1.4.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  * http://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 <string>
23 #include <fstream>
24 #include <vector>
25 #include <map>
26 #include <stdlib.h>
27 
28 namespace rtk
29 {
30 
39 class DbfField
40 {
41 public:
43  DbfField(std::string name, char type, unsigned char length, short recOffset);
44 
46  std::string GetName() {return m_Name;}
47  char GetType() {return m_Type;}
48  short GetLength() {return m_Length;}
50 
52  short GetRecOffset() {return m_RecOffset;}
53 
54 private:
55  std::string m_Name;
56  char m_Type;
57  short m_Length;
58  short m_RecOffset;
59 };
60 
71 class DbfFile
72 {
73 public:
75  DbfFile(std::string fileName);
76  ~DbfFile();
78 
80  bool is_open() { return m_Stream.is_open(); }
81 
83  size_t GetNumberOfRecords() { return m_Fields.size(); }
84 
87  bool ReadNextRecord();
88 
90  std::string GetFieldAsString(std::string fldName);
91 
92  double GetFieldAsDouble(std::string fldName) { return atof(GetFieldAsString(fldName).c_str() ); }
93 
94 private:
96  std::ifstream m_Stream;
97 
99  unsigned int m_NumRecords;
100  unsigned short m_RecordSize;
101  unsigned short m_HeaderSize;
102 
104  std::vector<DbfField> m_Fields;
105 
107  std::map<std::string, unsigned int> m_MapFieldNameIndex;
108 
110  char *m_Record;
111 };
112 }
113 
114 #endif
vcl_size_t GetNumberOfRecords()
Definition: rtkDbf.h:83
short m_RecOffset
Definition: rtkDbf.h:58
char GetType()
Definition: rtkDbf.h:47
char m_Type
Definition: rtkDbf.h:56
short GetLength()
Definition: rtkDbf.h:48
DbfField(std::string name, char type, unsigned char length, short recOffset)
double GetFieldAsDouble(std::string fldName)
Definition: rtkDbf.h:92
unsigned int m_NumRecords
Definition: rtkDbf.h:99
std::map< std::string, unsigned int > m_MapFieldNameIndex
Definition: rtkDbf.h:107
unsigned short m_RecordSize
Definition: rtkDbf.h:100
short GetRecOffset()
Definition: rtkDbf.h:52
std::ifstream m_Stream
Definition: rtkDbf.h:96
std::string GetName()
Definition: rtkDbf.h:46
std::vector< DbfField > m_Fields
Definition: rtkDbf.h:104
bool is_open()
Definition: rtkDbf.h:80
std::string m_Name
Definition: rtkDbf.h:55
unsigned short m_HeaderSize
Definition: rtkDbf.h:101
char * m_Record
Definition: rtkDbf.h:110
short m_Length
Definition: rtkDbf.h:57