• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

recordparser.h

Go to the documentation of this file.
00001 #ifndef EPT_APT_RECORDPARSER_H
00002 #define EPT_APT_RECORDPARSER_H
00003 
00008 /*
00009  * Copyright (C) 2007  Enrico Zini <enrico@enricozini.org>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00024  */
00025 
00026 #include <vector>
00027 #include <string>
00028 
00029 namespace ept {
00030 namespace apt {
00031 
00038 class RecordParser
00039 {
00041     std::string buffer;
00042 
00044     std::vector<size_t> ends;
00045 
00047     std::vector<size_t> sorted;
00048 
00049 public:
00050     RecordParser() {}
00051     RecordParser(const std::string& str) { scan(str); }
00052 
00054     void scan(const std::string& str);
00055 
00061     size_t index(const std::string& str) const;
00062 
00064     std::string field(size_t idx) const;
00065 
00067     std::string name(size_t idx) const;
00068 
00070     std::string lookup(size_t idx) const;
00071 
00073     std::string lookup(const std::string& name) const { return lookup(index(name)); }
00074 
00076     std::string operator[](size_t idx) const { return lookup(idx); }
00077 
00079     std::string operator[](const std::string& name) const { return lookup(name); }
00080 
00082     const std::string& record() const { return buffer; }
00083 
00085     std::string record() { return buffer; }
00086 
00088     size_t size() const { return ends.size(); }
00089 };
00090 
00091 }
00092 }
00093 
00094 // vim:set ts=4 sw=4:
00095 #endif

Generated on Wed Oct 27 2010 12:43:31 for libept by  doxygen 1.7.1