]> git.mxchange.org Git - simgear.git/blob - simgear/misc/tabbed_values.hxx
Removal of PLIB/SG from SimGear
[simgear.git] / simgear / misc / tabbed_values.hxx
1 // tabbed_values.hxx -- parse tab separated strings into fields
2 //
3 // Written by James Turner, started February 2003.
4 //
5 // Copyright (C) 2003 James Turner
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifndef SG_TABBED_VALUES_HXX
24 #define SG_TABBED_VALUES_HXX
25
26 #include <simgear/compiler.h>
27
28 #include <vector>
29 #include <string>
30
31 using std::vector;
32 using std::string;
33
34 class SGTabbedValues
35 {
36 public:
37         SGTabbedValues(const char* line);
38         
39         string operator[](const unsigned int) const;
40
41         bool isValueAt(const unsigned int) const;
42         
43         double getDoubleAt(const unsigned int) const;
44         char getCharAt(const unsigned int) const;
45         long getLongAt(const unsigned int) const;
46 private:
47         const char* fieldAt(const unsigned int offset) const;
48
49         const char* _line;
50         
51         /** this is first character of each field, if the field is empty
52         it will be the tab character. It is lazily built as needed, so
53         if only the first field is accessed (which is a common case) we
54         don't iterative over the whole line. */
55         mutable vector<char*> _fields;
56 };
57
58 #endif