schematic_database.hpp 1.6 KB

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