QSapecNG
 All Classes Functions Enumerations Properties
circuit.h
00001 /*
00002     SapecNG - Next Generation Symbolic Analysis Program for Electric Circuit
00003     Copyright (C) 2009, Michele Caini
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef CIRCUIT_H
00021 #define CIRCUIT_H
00022 
00023 
00024 #include "parser/parser.h"
00025 #include "model/graph.h"
00026 
00027 
00028 namespace sapecng
00029 {
00030 
00031 
00032 class circuit
00033 {
00034 
00035 friend class circuit_builder;
00036 
00037 public:
00038   typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
00039   typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
00040   typedef boost::graph_traits<Graph>::vertex_iterator vertex_iterator;
00041   typedef boost::graph_traits<Graph>::edge_iterator edge_iterator;
00042 
00043   circuit():
00044     vG_(0),
00045     iG_(0),
00046     reference_(0),
00047     out_(0)
00048   { vG_ = new Graph; iG_ = new Graph; }
00049 
00050   ~circuit()
00051     { delete vG_; delete iG_; }
00052 
00053   inline const
00054   std::map<std::string,std::string>&
00055   circuitProperties() const
00056     { return props_; }
00057 
00058   inline const Graph& vGraph() const
00059     { return *vG_; }
00060 
00061   inline const
00062   std::vector< edge_descriptor >&
00063   vGraph_order() const
00064     { return vG_o_; }
00065 
00066   inline const Graph& iGraph() const
00067     { return *iG_; }
00068 
00069   inline const
00070   std::vector< edge_descriptor >&
00071   iGraph_order() const
00072     { return iG_o_; }
00073 
00074   inline vertex_descriptor referenceNode() const
00075     { return reference_; }
00076 
00077   inline vertex_descriptor outNode() const
00078     { return out_; }
00079 
00080 private:
00081   std::map<std::string,std::string> props_;
00082 
00083   Graph* vG_;
00084   Graph* iG_;
00085   std::vector< edge_descriptor > vG_o_;
00086   std::vector< edge_descriptor > iG_o_;
00087 
00088   vertex_descriptor reference_;
00089   vertex_descriptor out_;
00090 
00091 };
00092 
00093 
00094 
00095 class circuit_builder: public abstract_builder
00096 {
00097 
00098 public:
00099   circuit_builder(circuit& circuit);
00100 
00101   void add_circuit_properties(std::map<std::string,std::string> map);
00102   void add_circuit_property(std::string name, std::string value);
00103 
00104   void add_wire_component(
00105       std::map<std::string,std::string> props =
00106         std::map<std::string,std::string>()
00107     );
00108 
00109   void add_out_component(
00110       unsigned int v,
00111       std::map<std::string,std::string> props =
00112         std::map<std::string,std::string>()
00113     );
00114 
00115   void add_dual_component(
00116       abstract_builder::dual_component_type c_type,
00117       std::string name,
00118       double value,
00119       bool symbolic,
00120       unsigned int va,
00121       unsigned int vb,
00122       std::map<std::string,std::string> props =
00123         std::map<std::string,std::string>()
00124     );
00125 
00126   void add_quad_component(
00127       abstract_builder::quad_component_type c_type,
00128       std::string name,
00129       double value,
00130       bool symbolic,
00131       unsigned int va,
00132       unsigned int vb,
00133       unsigned int vac,
00134       unsigned int vbc,
00135       std::map<std::string,std::string> props =
00136         std::map<std::string,std::string>()
00137     );
00138 
00139   void add_unknow_component(
00140       std::map<std::string,std::string> props =
00141         std::map<std::string,std::string>()
00142     ) { }
00143 
00144   void begin_userdef_component(
00145       std::string name,
00146       std::map<std::string,std::string> props =
00147         std::map<std::string,std::string>()
00148     ) { }
00149 
00150   void end_userdef_component(
00151       std::string name,
00152       std::map<std::string,std::string> props =
00153         std::map<std::string,std::string>()
00154     ) { }
00155 
00156   void flush();
00157 
00158 private:
00159   void try_add_block();
00160   void replace_requested(circuit::vertex_descriptor vertex);
00161 
00162   void add_edge(
00163       circuit::vertex_descriptor iva,
00164       circuit::vertex_descriptor ivb,
00165       circuit::vertex_descriptor vva,
00166       circuit::vertex_descriptor vvb,
00167       EdgeType type,
00168       std::string name,
00169       double value,
00170       int degree,
00171       bool symbolic,
00172       std::map<std::string,std::string> props
00173     );
00174 
00175 private:
00176   circuit& circuit_;
00177   std::list<circuit::vertex_descriptor> requested_;
00178   bool has_block_;
00179 
00180   std::string prefix_;
00181   std::vector<std::string> pstack_;
00182 
00183 };
00184 
00185 
00186 }
00187 
00188 
00189 #endif // CIRCUIT_H
 All Classes Functions Enumerations Properties