QSapecNG
 All Classes Functions Enumerations Properties
parser_factory.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 PARSER_FACTORY_H
00021 #define PARSER_FaCTORY_H
00022 
00023 
00024 #include <parser/parser.h>
00025 #include <parser/ir_circuit.h>
00026 #include <parser/crc_circuit.h>
00027 
00028 
00029 namespace sapecng
00030 {
00031 
00032 
00033 
00034 class builder_factory
00035 {
00036 
00037 public:
00038   enum b_type
00039     { INFO, XML, CRC };
00040 
00041   static abstract_builder* builder(
00042       builder_factory::b_type type,
00043       std::basic_ostream<
00044           boost::property_tree::ptree::key_type::value_type
00045         >& stream
00046     )
00047   {
00048     switch(type)
00049     {
00050     case INFO:
00051       return new info_builder(stream);
00052     case XML:
00053       return new xml_builder(stream);
00054     case CRC:
00055       return new crc_builder(stream);
00056     default:
00057       break;
00058     }
00059 
00060     return 0;
00061   }
00062 
00063   static abstract_builder* builder(
00064       std::string type,
00065       std::basic_ostream<
00066           boost::property_tree::ptree::key_type::value_type
00067         >& stream
00068     )
00069   {
00070     if(type == "info")
00071       return builder(INFO, stream);
00072 
00073     if(type == "xml")
00074       return builder(XML, stream);
00075 
00076     if(type == "crc")
00077       return builder(CRC, stream);
00078 
00079     return 0;
00080   }
00081 
00082 };
00083 
00084 
00085 
00086 class parser_factory
00087 {
00088 
00089 public:
00090   enum p_type
00091     { INFO, XML };
00092 
00093   static abstract_parser* parser(
00094       parser_factory::p_type type,
00095       std::basic_istream<
00096           boost::property_tree::ptree::key_type::value_type
00097         >& stream
00098     )
00099   {
00100     switch(type)
00101     {
00102     case INFO:
00103       return new info_parser(stream);
00104     case XML:
00105       return new xml_parser(stream);
00106     default:
00107       break;
00108     }
00109 
00110     return 0;
00111   }
00112 
00113   static abstract_parser* parser(
00114       std::string type,
00115       std::basic_istream<
00116           boost::property_tree::ptree::key_type::value_type
00117         >& stream
00118     )
00119   {
00120     if(type == "info")
00121       return parser(INFO, stream);
00122 
00123     if(type == "xml")
00124       return parser(XML, stream);
00125 
00126     return 0;
00127   }
00128 
00129 };
00130 
00131 
00132 
00133 }
00134 
00135 
00136 #endif // PARSER_FACTORY_H
 All Classes Functions Enumerations Properties