|
UniSet
2.6.0
|
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 Schema_H_ 00018 #define Schema_H_ 00019 // -------------------------------------------------------------------------- 00020 #include <memory> 00021 #include <unordered_map> 00022 #include "Element.h" 00023 #include "Schema.h" 00024 // -------------------------------------------------------------------------- 00025 namespace uniset 00026 { 00027 // -------------------------------------------------------------------------- 00028 class Schema 00029 { 00030 public: 00031 Schema(); 00032 virtual ~Schema(); 00033 00034 std::shared_ptr<Element> manage( std::shared_ptr<Element> el ); 00035 00036 void remove( std::shared_ptr<Element> el ); 00037 00038 void link( Element::ElementID rootID, Element::ElementID childID, int numIn ); 00039 void unlink( Element::ElementID rootID, Element::ElementID childID ); 00040 void extlink( const std::string& name, Element::ElementID childID, int numIn ); 00041 00042 void setIn( Element::ElementID ID, int inNum, bool state ); 00043 bool getOut( Element::ElementID ID ); 00044 00045 struct INLink; 00046 struct EXTLink; 00047 struct EXTOut; 00048 00049 typedef std::unordered_map<Element::ElementID, std::shared_ptr<Element>> ElementMap; 00050 typedef std::list<INLink> InternalList; 00051 typedef std::list<EXTLink> ExternalList; 00052 typedef std::list<EXTOut> OutputsList; 00053 00054 // map iterator 00055 typedef ElementMap::const_iterator iterator; 00056 inline Schema::iterator begin() 00057 { 00058 return emap.begin(); 00059 } 00060 inline Schema::iterator end() 00061 { 00062 return emap.end(); 00063 } 00064 inline int size() 00065 { 00066 return emap.size(); 00067 } 00068 inline bool empty() 00069 { 00070 return emap.empty(); 00071 } 00072 00073 // int. list iterator 00074 typedef InternalList::const_iterator INTiterator; 00075 inline Schema::INTiterator intBegin() 00076 { 00077 return inLinks.begin(); 00078 } 00079 inline Schema::INTiterator intEnd() 00080 { 00081 return inLinks.end(); 00082 } 00083 inline int intSize() 00084 { 00085 return inLinks.size(); 00086 } 00087 inline bool intEmpty() 00088 { 00089 return inLinks.empty(); 00090 } 00091 00092 // ext. list iterator 00093 typedef ExternalList::const_iterator EXTiterator; 00094 inline Schema::EXTiterator extBegin() 00095 { 00096 return extLinks.begin(); 00097 } 00098 inline Schema::EXTiterator extEnd() 00099 { 00100 return extLinks.end(); 00101 } 00102 inline int extSize() 00103 { 00104 return extLinks.size(); 00105 } 00106 inline bool extEmpty() 00107 { 00108 return extLinks.empty(); 00109 } 00110 00111 // ext. out iterator 00112 typedef OutputsList::const_iterator OUTiterator; 00113 inline Schema::OUTiterator outBegin() 00114 { 00115 return outList.begin(); 00116 } 00117 inline Schema::OUTiterator outEnd() 00118 { 00119 return outList.end(); 00120 } 00121 inline int outSize() 00122 { 00123 return outList.size(); 00124 } 00125 inline bool outEmpty() 00126 { 00127 return outList.empty(); 00128 } 00129 00130 // find 00131 std::shared_ptr<Element> find(Element::ElementID id); 00132 std::shared_ptr<Element> findExtLink(const std::string& name); 00133 std::shared_ptr<Element> findOut(const std::string& name); 00134 00135 // ----------------------------------------------- 00136 // внутренее соединения 00137 // между элементами 00138 struct INLink 00139 { 00140 INLink(std::shared_ptr<Element> f, std::shared_ptr<Element> t, int ni): 00141 numInput(ni) {} 00142 INLink(): numInput(0) {} 00143 00144 std::shared_ptr<Element> from; 00145 std::shared_ptr<Element> to; 00146 int numInput; 00147 }; 00148 00149 // внешнее соединение 00150 // что-то на вход элемента 00151 struct EXTLink 00152 { 00153 EXTLink( const std::string& n, std::shared_ptr<Element> t, int ni): 00154 name(n), to(t), numInput(ni) {} 00155 EXTLink(): name(""), numInput(0) {} 00156 00157 std::string name; 00158 std::shared_ptr<Element> to; 00159 int numInput; 00160 }; 00161 00162 // наружный выход 00163 struct EXTOut 00164 { 00165 EXTOut( const std::string& n, std::shared_ptr<Element>& f): 00166 name(n), from(f) {} 00167 EXTOut(): name("") {} 00168 00169 std::string name; 00170 std::shared_ptr<Element> from; 00171 }; 00172 00173 protected: 00174 ElementMap emap; // список элеметов 00175 InternalList inLinks; 00176 ExternalList extLinks; 00177 OutputsList outList; 00178 00179 private: 00180 }; 00181 // --------------------------------------------------------------------------- 00182 class SchemaXML: 00183 public Schema 00184 { 00185 public: 00186 SchemaXML(); 00187 virtual ~SchemaXML(); 00188 00189 void read( const std::string& xmlfile ); 00190 00191 protected: 00192 }; 00193 // -------------------------------------------------------------------------- 00194 } // end of namespace uniset 00195 // --------------------------------------------------------------------------- 00196 #endif
1.7.6.1