1 /* 2 * CVirtualNet.hh 3 * 4 * Copyright 2014-2020 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 CVIRTUALNET_HH_ 25 #define CVIRTUALNET_HH_ 26 27 #include "Cvc.hh" 28 29 #include "CPower.hh" 30 #include "mmappable_vector.h" 31 32 using namespace mmap_allocator_namespace; 33 34 class CVirtualNet; 35 class CVirtualNetVector; 36 37 class CBaseVirtualNet { 38 public: 39 netId_t nextNetId = UNKNOWN_NET; 40 resistance_t resistance = 0; 41 42 void operator= (CVirtualNet& theEqualNet); 43 }; 44 45 class CVirtualNetMappedVector : public mmappable_vector<CVirtualNet> { 46 public: 47 CVirtualNetMappedVector(mmap_allocator<CVirtualNet> theAllocator); 48 void operator= (CVirtualNetVector& theNetVector); 49 }; 50 51 class CVirtualNet { 52 public: 53 netId_t nextNetId = UNKNOWN_NET; 54 resistance_t resistance = 0; 55 netId_t finalNetId = UNKNOWN_NET; 56 resistance_t finalResistance = 0; 57 netId_t backupNetId = UNKNOWN_NET; 58 59 void operator= (CVirtualNet& theEqualNet); operator ==(CVirtualNet & theTestNet)60 inline bool operator== (CVirtualNet& theTestNet) { return (nextNetId == theTestNet.nextNetId && resistance == theTestNet.resistance); }; 61 CVirtualNet& operator() (CVirtualNetVector& theVirtualNet_v, netId_t theNetId); 62 void Copy(const CVirtualNet& theBase); 63 void Print(ostream& theOutputFile); 64 }; 65 66 class CVirtualNetVector : public vector<CVirtualNet> { 67 public: 68 eventKey_t lastUpdate; 69 vector<eventKey_t> lastUpdate_v; 70 powerType_t calculatedBit; 71 CVirtualNetVector(powerType_t theCalculatedBit)72 CVirtualNetVector(powerType_t theCalculatedBit) : calculatedBit(theCalculatedBit) {}; 73 resize(size_type n)74 inline void resize (size_type n) { vector<CVirtualNet>::resize(n); lastUpdate_v.resize(n, 0); }; reserve(size_type n)75 inline void reserve (size_type n) { vector<CVirtualNet>::reserve(n); lastUpdate_v.reserve(n); }; shrink_to_fit()76 inline void shrink_to_fit() { vector<CVirtualNet>::shrink_to_fit(); lastUpdate_v.shrink_to_fit(); }; IsTerminal(netId_t theNetId)77 inline bool IsTerminal(netId_t theNetId) { return ( theNetId == (*this)[theNetId].nextNetId ); } 78 void Print(string theTitle = "", string theIndentation = ""); 79 void Print(CNetIdVector& theEquivalentNet_v, string theTitle = "", string theIndentation = ""); 80 void Set(netId_t theNetId, netId_t theNextNet, resistance_t theResistance, eventKey_t theTime); 81 void DebugVirtualNet(netId_t theNetId, string theTitle = "", ostream& theOutputFile = cout); 82 void BackupVirtualNets(); InitializeUpdateArray()83 inline void InitializeUpdateArray() { lastUpdate_v.resize(size(), 0); }; ClearUpdateArray()84 inline void ClearUpdateArray() { lastUpdate_v.clear(); }; 85 86 }; 87 88 #endif /* CVIRTUALNET_HH_ */ 89