1 /*
2 Copyright 2010 Intel Corporation
3 
4 Use, modification and distribution are subject to the Boost Software License,
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt).
7 */
8 
9 //schematic_database.hpp
10 #ifndef BOOST_POLYGON_TUTORIAL_SCHEMATIC_DATABASE_HPP
11 #define BOOST_POLYGON_TUTORIAL_SCHEMATIC_DATABASE_HPP
12 #include <string>
13 #include <fstream>
14 #include <map>
15 #include <set>
16 #include "device.hpp"
17 
18 struct schematic_database{
19   std::vector<device> devices;
20   std::map<std::string, std::set<std::size_t> > nets;
21 };
22 
23 //given a vector of devices populate the map of net name to set of device index
extract_netlist(std::map<std::string,std::set<std::size_t>> & nets,std::vector<device> & devices)24 inline void extract_netlist(std::map<std::string, std::set<std::size_t> >& nets,
25                             std::vector<device>& devices) {
26   for(std::size_t i = 0; i < devices.size(); ++i) {
27     for(std::size_t j = 0; j < devices[i].terminals.size(); ++j) {
28       //create association between net name and device id
29       nets[devices[i].terminals[j]].insert(nets[devices[i].terminals[j]].end(), i);
30     }
31   }
32 }
33 
parse_schematic_database(schematic_database & schematic,std::ifstream & sin)34 inline void parse_schematic_database(schematic_database& schematic,
35                                      std::ifstream& sin) {
36   std::vector<device>& devices = schematic.devices;
37   while(!sin.eof()) {
38     std::string type_id;
39     sin >> type_id;
40     if(type_id == "Device") {
41       device d;
42       sin >> d;
43       devices.push_back(d);
44     } else if (type_id == "Pin") {
45       std::string net;
46       sin >> net;
47       device d;
48       d.type = "PIN";
49       d.terminals.push_back(net);
50       devices.push_back(d);
51     } else if (type_id == "") {
52       break;
53     }
54   }
55   extract_netlist(schematic.nets, devices);
56 }
57 
58 #endif
59