1 /*
2  * CCircuit.hh
3  *
4  * Copyright 2014-2018 D. Mitch Bailey  cvc at shuharisystem dot com
5  *
6  * This file is part of cvc.
7  *
8  * cvc is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * cvc is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with cvc.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * You can download cvc from https://github.com/d-m-bailey/cvc.git
22  */
23 
24 #ifndef CCIRCUIT_HH_
25 #define CCIRCUIT_HH_
26 
27 #include "Cvc.hh"
28 
29 class CCvcDb;
30 #include "CDevice.hh"
31 #include "CInstance.hh"
32 #include "CFixedText.hh"
33 #include "gzstream.h"
34 
35 class CCircuit {
36 	// subcircuit instance/device name to deviceID map
37 	static text_t lastDeviceMap;
38 	static CTextDeviceIdMap localDeviceIdMap;
39 	static text_t lastSubcircuitMap;
40 	static CTextDeviceIdMap localSubcircuitIdMap;
41 public:
42 	deviceId_t errorLimit = UNKNOWN_DEVICE;
43 	text_t name;
44 	// local signal to local netID Map
45 	CTextNetIdMap localSignalIdMap;
46 	// temporary list to convert to vector
47 	CTextList	internalSignalList;
48 	// local netID to signal name map
49 	CTextVector	internalSignal_v;
50 	CDevicePtrVector	devicePtr_v;
51 	CDevicePtrVector	subcircuitPtr_v;
52 	vector<array<deviceId_t, 5>>	deviceErrorCount_v;
53 	vector<array<deviceId_t, 5>>	devicePrintCount_v;
54 	CInstanceIdVector instanceId_v;
55 	CInstanceIdVector instanceHashId_v;
56 
57 	netId_t	portCount = 0;
58 	// total items for this circuit and all subcircuits
59 	netId_t	netCount = 0;
60 	deviceId_t	deviceCount = 0;
61 	// the number of children
62 	instanceId_t	subcircuitCount = 0;
63 	// the number of instantiations
64 	instanceId_t	instanceCount = 0;
65 	string	checksum = "";
66 
67 //	deviceId_t		errorCount = 0;
68 //	deviceId_t		warningCount = 0;
69 	bool	linked = false;
70 
LocalNetCount()71 	inline netId_t	LocalNetCount() { return ( localSignalIdMap.size() - portCount); }
72 
73 	void AddPortSignalIds(CTextList * thePortList_p);
74 	void SetSignalIds(CTextList * theSignalList_p, CNetIdVector & theSignalId_v);
75 	deviceId_t GetLocalDeviceId(text_t theName);
76 	deviceId_t GetLocalSubcircuitId(text_t theName);
77 	void LoadDevices(CDevicePtrList * theDeviceList_p);
78 
79 	void CountObjectsAndLinkSubcircuits(unordered_map<text_t, CCircuit *> & theCircuitNameMap);
80 	void CountInstantiations();
81 
82 	void Print(const string theIndentation = "");
83 
84 	void AllocateInstances(CCvcDb * theCvcDb_p, instanceId_t theFirstInstanceId);
85 };
86 
87 class CTextCircuitPtrMap : public unordered_map<text_t, CCircuit *> {
88 public:
CTextCircuitPtrMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)89 	CTextCircuitPtrMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);}
90 };
91 
92 static set<modelType_t> emptyModelList;
93 
94 class CCircuitPtrList : public list<CCircuit *> {
95 private:
96 public:
97 	CFixedText	cdlText;
98 	CTextCircuitPtrMap  circuitNameMap;
99 	CFixedText	parameterText;
100 	int			errorCount = 0;
101 	int			warningCount = 0;
102 //	CCircuitPtrList();
103 //	CCircuitPtrList(int count, CDevice new_instance);
104 	void Clear();
105 
106 	void Print(const string theIndentation = "", const string theHeading = "CircuitList>");
107 //	void CreateDatabase(const string theTopBlockName);
108 	CCircuit * FindCircuit(const string theSearchCircuit);
109 	void SetChecksum(const string theSearchCircuit, const string theChecksum);
110 	void PrintAndResetCircuitErrors(CCvcDb * theCvcDb_p, deviceId_t theErrorLimit, ofstream & theLogFile, ogzstream & theErrorFile,
111 		string theSummaryHeading = "", int theSubErrorIndex = 0, set<modelType_t> & theModelList = emptyModelList);
112 };
113 
114 
115 #endif /* CCIRCUIT_HH_ */
116