1 /*
2  * CDevice.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 CDEVICE_HH_
25 #define CDEVICE_HH_
26 
27 #include "Cvc.hh"
28 
29 class CCvcDb;
30 #include "CModel.hh"
31 
32 class CCircuit;
33 
34 class CDevice {
35 public:
36 	text_t name;
37 	CTextList * signalList_p;
38 	CNetIdVector signalId_v;
39 	CCircuit * parent_p;
40 
41 	union {
42 		CCircuit * master_p;  // for subcircuits
43 		CModel * model_p;  // for devices
44 	};
45 	union {
46 		text_t masterName;  // for subcircuits
47 		CDevice * nextDevice_p;  // for devices, next device of the same model
48 	};
49 	text_t parameters;
50 	deviceId_t offset;  // offset in circuit (devices and subcircuit instances counted separately)
51 	bool	sourceDrainSet = false;
52 	bool	sourceDrainSwapOk = true;
53 
54 	~CDevice();
AppendSignal(text_t theNewSignal)55 	inline void AppendSignal (text_t theNewSignal) {
56 		// skip null signals (missing bias)
57 		if ( theNewSignal ) signalList_p->push_back(theNewSignal);
58 	}
IsSubcircuit()59 	inline bool IsSubcircuit() { return name[0] == 'X' && parameters == text_t(NULL); }
IsBox()60 	inline bool IsBox() { return name[0] == 'X' && parameters != text_t(NULL); }
IsMosfet()61 	inline bool IsMosfet() { return name[0] == 'M'; }
IsCapacitor()62 	inline bool IsCapacitor() { return name[0] == 'C'; }
IsDiode()63 	inline bool IsDiode() { return name[0] == 'D'; }
IsResistor()64 	inline bool IsResistor() { return name[0] == 'R'; }
IsSwitch()65 	inline bool IsSwitch() { return name[0] == 'S'; }
IsFuse()66 	inline bool IsFuse() { return name[0] == 'F'; }
67 
68 	void Print(CTextVector& theSignalName_v, const string theIndentation = "");
69 	void Print(CTextVector& theSignalName_v, deviceId_t theDeviceId,
70 			const string theIndentation = "");
71 
72 	instanceId_t MakePortHash(CNetIdVector & theLocalToGlobalNetId_v);
73 	instanceId_t FindParallelInstance(CCvcDb * theCCvcDb_p, instanceId_t theInstanceId, CNetIdVector & theLocalToGlobalNetId_v);
74 };
75 
76 class CDevicePtrList : public list<CDevice *> {
77 public:
78 	deviceId_t	subcircuitCount = 0;
79 
DeviceCount()80 	inline deviceId_t	DeviceCount() { return (size() - subcircuitCount); }
SubcircuitCount()81 	inline deviceId_t	SubcircuitCount() { return subcircuitCount; }
82 	void Print(CTextVector& theSignalName_v, const string theIndentation = "",
83 			const string theHeading = "DeviceList>");
84 };
85 
86 class CDevicePtrVector : public vector<CDevice *> {
87 public:
88 
89 	~CDevicePtrVector();
90 	void Print(CTextVector& theSignalName_v, const string theIndentation = "",
91 			const string theHeading = "DeviceList>");
92 	void Print(CTextVector& theSignalName_v, CCircuit * theParent_p,
93 			const string theIndentation = "", const string theHeading = "DeviceList>");
94 };
95 
96 #endif /* CDEVICE_HH_ */
97