1 /*
2  * CModel.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 CMODEL_HH_
25 #define CMODEL_HH_
26 
27 #include "Cvc.hh"
28 
29 class CDevice;
30 class CPowerPtrMap;
31 
32 #include "CNormalValue.hh"
33 #include "CCondition.hh"
34 #include "CParameterMap.hh"
35 #include <regex>
36 
37 class CModelCheck {
38 public:
39 	string check = "";
40 	string parameter = "";
41 	bool isVoltage = false;
42 	string minInclusiveText = "";
43 	string minExclusiveText = "";
44 	string maxInclusiveText = "";
45 	string maxExclusiveText = "";
46 	float minInclusiveValue = 0.;
47 	float minExclusiveValue = 0.;
48 	float maxInclusiveValue = 0.;
49 	float maxExclusiveValue = 0.;
50 	voltage_t minInclusiveVoltage = 0.;
51 	voltage_t minExclusiveVoltage = 0.;
52 	voltage_t maxInclusiveVoltage = 0.;
53 	voltage_t maxExclusiveVoltage = 0.;
54 
55 	CModelCheck(string theCheck, string theParameter, string theInclusiveMin, string theExclusiveMin, string theInclusiveMax, string theExclusiveMax );
56 	void SetValue(string theParameter, voltage_t &theVoltage, float &theValue);
57 
58 };
59 
60 class CModel {
61 public:
62 	string	name;
63 
64 	string	maxVdsDefinition = "";
65 	string	maxVgsDefinition = "";
66 	string	maxVbsDefinition = "";
67 	string	maxVbgDefinition = "";
68 
69 	string	vthDefinition = "";
70 
71 	voltage_t	maxVds = UNKNOWN_VOLTAGE;
72 	voltage_t	maxVgs = UNKNOWN_VOLTAGE;
73 	voltage_t	maxVbs = UNKNOWN_VOLTAGE;
74 	voltage_t	maxVbg = UNKNOWN_VOLTAGE;
75 
76 	voltage_t	Vth = UNKNOWN_VOLTAGE;
77 
78 	string	resistanceDefinition;
79 
80 	string	baseType = "";
81 
82 	bool isLDD = false;
83 	bool validModel = true;
84 
85 	modelType_t type = UNKNOWN;
86 
87 	CConditionPtrList	conditionPtrList;
88 	string cellFilter = "";
89 	regex * cellFilterRegex_p = NULL;
90 	list <pair<int, int>>	diodeList;
91 
92 	CDevice *	firstDevice_p = NULL;
93 
94 	string	definition;
95 
96 	forward_list<CModelCheck> checkList;
97 
98 	CModel(string theParameterString);
99 	void Clear();
100 	size_t ModelCount();
101 	bool ParameterMatch(CParameterMap& theParameterMap,text_t theCellName);
102 	void CreateConditions(string theConditionString);
103 	void SetDiodes (string theDiodeString);
104 
105 	void Print(ostream & theLogFile = cout, bool thePrintDeviceListFlag = false, string theIndentation = "");
106 	string ConditionString();
107 };
108 
109 class CModelList : public list<CModel> {
110 public:
111 	int		Vth = UNKNOWN_VOLTAGE;
112 	string	vthDefinition;
113 };
114 
115 class CTextModelPtrMap : public unordered_map<text_t, CModel *> {
116 public:
CTextModelPtrMap(float theLoadFactor=DEFAULT_LOAD_FACTOR)117 	CTextModelPtrMap(float theLoadFactor = DEFAULT_LOAD_FACTOR) {max_load_factor(theLoadFactor);}
118 };
119 
120 class CModelListMap : public map<string, CModelList> {
121 public:
122 	bool hasError;
123 	string filename;
124 
125 	void Clear();
126 	void AddModel(string theParameterString);
127 	CModel * FindModel(text_t theCellName, text_t theParameterText, CTextResistanceMap & theParameterResistanceMap, ostream& theLogFile);
128 	CModelList * FindModelList(string theModelName);
129 	void Print(ostream & theLogFile, string theIndentation = "");
130 	void DebugPrint(string theIndentation = "");
131 	returnCode_t SetVoltageTolerances(teestream & theReportFile, CPowerPtrMap & thePowerMacroPtrMap);
132 };
133 
134 #endif /* CMODEL_HH_ */
135