libept
recordparser.h
Go to the documentation of this file.
1 #ifndef EPT_APT_RECORDPARSER_H
2 #define EPT_APT_RECORDPARSER_H
3 
8 /*
9  * Copyright (C) 2007 Enrico Zini <enrico@enricozini.org>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */
25 
26 #include <vector>
27 #include <string>
28 
29 namespace ept {
30 namespace apt {
31 
39 {
41  std::string buffer;
42 
44  std::vector<size_t> ends;
45 
47  std::vector<size_t> sorted;
48 
49 public:
51  RecordParser(const std::string& str) { scan(str); }
52 
54  void scan(const std::string& str);
55 
61  size_t index(const std::string& str) const;
62 
64  std::string field(size_t idx) const;
65 
67  std::string name(size_t idx) const;
68 
70  std::string lookup(size_t idx) const;
71 
73  std::string lookup(const std::string& name) const { return lookup(index(name)); }
74 
76  std::string operator[](size_t idx) const { return lookup(idx); }
77 
79  std::string operator[](const std::string& name) const { return lookup(name); }
80 
82  const std::string& record() const { return buffer; }
83 
85  std::string record() { return buffer; }
86 
88  size_t size() const { return ends.size(); }
89 };
90 
91 }
92 }
93 
94 // vim:set ts=4 sw=4:
95 #endif