UniSet  2.6.0
ObjectIndex_idXML.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 // --------------------------------------------------------------------------
00017 #ifndef ObjectIndex_idXML_H_
00018 #define ObjectIndex_idXML_H_
00019 // --------------------------------------------------------------------------
00020 #include <unordered_map>
00021 #include <string>
00022 #include "ObjectIndex.h"
00023 #include "UniXML.h"
00024 // --------------------------------------------------------------------------
00025 namespace uniset
00026 {
00027 
00028 class ObjectIndex_idXML:
00029     public uniset::ObjectIndex
00030 {
00031     public:
00032         ObjectIndex_idXML( const std::string& xmlfile );
00033         ObjectIndex_idXML( const std::shared_ptr<UniXML>& xml );
00034         virtual ~ObjectIndex_idXML();
00035 
00036         virtual const uniset::ObjectInfo* getObjectInfo( const uniset::ObjectId ) const noexcept override;
00037         virtual const uniset::ObjectInfo* getObjectInfo( const std::string& name ) const noexcept override;
00038         virtual uniset::ObjectId getIdByName( const std::string& name ) const noexcept override;
00039         virtual std::string getMapName( const uniset::ObjectId id ) const noexcept override;
00040         virtual std::string getTextName( const uniset::ObjectId id ) const noexcept override;
00041 
00042         virtual std::ostream& printMap( std::ostream& os ) const noexcept override;
00043         friend std::ostream& operator<<(std::ostream& os, ObjectIndex_idXML& oi );
00044 
00045     protected:
00046         void build( const std::shared_ptr<UniXML>& xml );
00047         void read_section( const std::shared_ptr<UniXML>& xml, const std::string& sec );
00048         void read_nodes( const std::shared_ptr<UniXML>& xml, const std::string& sec );
00049 
00050     private:
00051         typedef std::unordered_map<uniset::ObjectId, uniset::ObjectInfo> MapObjects;
00052         MapObjects omap;
00053 
00054         typedef std::unordered_map<std::string, uniset::ObjectId> MapObjectKey;
00055         MapObjectKey mok; // для обратного писка
00056 };
00057 // -------------------------------------------------------------------------
00058 } // end of uniset namespace
00059 // -----------------------------------------------------------------------------------------
00060 #endif