UniSet  2.8.0
ObjectIndex_XML.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
20 // --------------------------------------------------------------------------
21 #ifndef ObjectIndex_XML_H_
22 #define ObjectIndex_XML_H_
23 // --------------------------------------------------------------------------
24 #include <unordered_map>
25 #include <memory>
26 #include <vector>
27 #include <string>
28 #include "ObjectIndex.h"
29 #include "UniXML.h"
30 // --------------------------------------------------------------------------
31 namespace uniset
32 {
33 
39  public ObjectIndex
40  {
41  public:
42  ObjectIndex_XML(const std::string& xmlfile, size_t minSize = 1000 );
43  ObjectIndex_XML( const std::shared_ptr<UniXML>& xml, size_t minSize = 1000 );
44  virtual ~ObjectIndex_XML();
45 
46  virtual const uniset::ObjectInfo* getObjectInfo( const ObjectId ) const noexcept override;
47  virtual const uniset::ObjectInfo* getObjectInfo( const std::string& name ) const noexcept override;
48  virtual ObjectId getIdByName( const std::string& name ) const noexcept override;
49  virtual std::string getMapName( const ObjectId id ) const noexcept override;
50  virtual std::string getTextName( const ObjectId id ) const noexcept override;
51 
52  virtual std::ostream& printMap(std::ostream& os) const noexcept override;
53  friend std::ostream& operator<<(std::ostream& os, ObjectIndex_XML& oi );
54 
55  protected:
56  void build( const std::shared_ptr<UniXML>& xml );
57  size_t read_section(const std::shared_ptr<UniXML>& xml, const std::string& sec, size_t ind );
58  size_t read_nodes( const std::shared_ptr<UniXML>& xml, const std::string& sec, size_t ind );
59 
60  private:
61  typedef std::unordered_map<std::string, ObjectId> MapObjectKey;
62  MapObjectKey mok; // для обратного писка
63  std::vector<ObjectInfo> omap; // для прямого поиска
64  };
65  // -----------------------------------------------------------------------------------------
66 } // end of namespace
67 // -----------------------------------------------------------------------------------------
68 #endif
Definition: CommonEventLoop.h:14
Definition: ObjectIndex_XML.h:38
Definition: ObjectIndex.h:31
virtual std::string getTextName(const ObjectId id) const noexcept override
Definition: ObjectIndex_XML.cc:72
Definition: UniSetTypes.h:144
virtual ObjectId getIdByName(const std::string &name) const noexcept override
Definition: ObjectIndex_XML.cc:50
virtual std::string getMapName(const ObjectId id) const noexcept override
Definition: ObjectIndex_XML.cc:64
long ObjectId
Definition: UniSetTypes_i.idl:30