UniSet  2.6.0
ObjectIndex_XML.h
00001 /*
00002  * Copyright (c) 2015 Pavel Vainerman.
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as
00006  * published by the Free Software Foundation, version 2.1.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00011  * Lesser General Lesser Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00015  */
00016 // --------------------------------------------------------------------------
00020 // --------------------------------------------------------------------------
00021 #ifndef ObjectIndex_XML_H_
00022 #define ObjectIndex_XML_H_
00023 // --------------------------------------------------------------------------
00024 #include <unordered_map>
00025 #include <memory>
00026 #include <vector>
00027 #include <string>
00028 #include "ObjectIndex.h"
00029 #include "UniXML.h"
00030 // --------------------------------------------------------------------------
00031 namespace uniset
00032 {
00033 
00035 class ObjectIndex_XML:
00036     public ObjectIndex
00037 {
00038     public:
00039         ObjectIndex_XML(const std::string& xmlfile, size_t minSize = 1000 );
00040         ObjectIndex_XML( const std::shared_ptr<UniXML>& xml, size_t minSize = 1000 );
00041         virtual ~ObjectIndex_XML();
00042 
00043         virtual const uniset::ObjectInfo* getObjectInfo( const ObjectId ) const noexcept override;
00044         virtual const uniset::ObjectInfo* getObjectInfo( const std::string& name ) const noexcept override;
00045         virtual ObjectId getIdByName( const std::string& name ) const noexcept override;
00046         virtual std::string getMapName( const ObjectId id ) const noexcept override;
00047         virtual std::string getTextName( const ObjectId id ) const noexcept override;
00048 
00049         virtual std::ostream& printMap(std::ostream& os) const noexcept override;
00050         friend std::ostream& operator<<(std::ostream& os, ObjectIndex_XML& oi );
00051 
00052     protected:
00053         void build( const std::shared_ptr<UniXML>& xml );
00054         size_t read_section(const std::shared_ptr<UniXML>& xml, const std::string& sec, size_t ind );
00055         size_t read_nodes( const std::shared_ptr<UniXML>& xml, const std::string& sec, size_t ind );
00056 
00057     private:
00058         typedef std::unordered_map<std::string, ObjectId> MapObjectKey;
00059         MapObjectKey mok; // для обратного писка
00060         std::vector<ObjectInfo> omap; // для прямого поиска
00061 };
00062 // -----------------------------------------------------------------------------------------
00063 }    // end of namespace
00064 // -----------------------------------------------------------------------------------------
00065 #endif