VCDFile.cpp
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 #include "VCDFile.hpp"
5 
6 
7 //! Instance a new VCD file container.
9 
10 }
11 
12 //! Destructor
14 
15  // Delete signals and scopes.
16 
17  for (VCDScope * scope : this -> scopes) {
18 
19  for (VCDSignal * signal : scope -> signals) {
20  delete signal;
21  }
22 
23  delete scope;
24  }
25 
26  // Delete signal values.
27 
28  for(auto hash_val = this -> val_map.begin();
29  hash_val != this -> val_map.end();
30  ++hash_val)
31  {
32  for(auto vals = hash_val -> second -> begin();
33  vals != hash_val -> second -> end();
34  ++vals)
35  {
36  delete (*vals) -> value;
37  delete *vals;
38  }
39 
40  delete hash_val -> second;
41  }
42 
43 }
44 
45 
46 /*!
47 @brief Add a new scope object to the VCD file
48 */
50  VCDScope * s
51 ){
52  this -> scopes.push_back(s);
53 }
54 
55 
56 /*!
57 @brief Add a new signal object to the VCD file
58 */
60  VCDSignal * s
61 ){
62  this -> signals.push_back(s);
63 
64  // Add a timestream entry
65  if(val_map.find(s -> hash) == val_map.end()) {
66  // Values will be populated later.
67  val_map[s -> hash] = new VCDSignalValues();
68  }
69 }
70 
71 
72 /*!
73  */
75  for (auto &scope : scopes) {
76  if (scope->name == name) {
77  return scope;
78  }
79  }
80  return nullptr;
81 }
82 
83 
84 /*!
85 @brief Add a new signal value to the VCD file, tagged by time.
86 */
88  VCDTimedValue * time_val,
89  VCDSignalHash hash
90 ){
91  this -> val_map[hash] -> push_back(time_val);
92 }
93 
94 
95 /*!
96 */
97 std::vector<VCDTime>* VCDFile::get_timestamps(){
98  return &this -> times;
99 }
100 
101 
102 /*!
103 */
104 std::vector<VCDScope*>* VCDFile::get_scopes(){
105  return &this -> scopes;
106 }
107 
108 
109 /*!
110 */
111 std::vector<VCDSignal*>* VCDFile::get_signals(){
112  return &this -> signals;
113 }
114 
115 
116 /*!
117 */
119  VCDTime time
120 ){
121  this -> times.push_back(time);
122 }
123 
124 /*!
125 */
127  const VCDSignalHash& hash,
128  VCDTime time,
129  bool erase_prior
130 ){
131  auto find = val_map.find(hash);
132  if(find == this -> val_map.end()) {
133  return nullptr;
134  }
135 
136  VCDSignalValues * vals = find->second;
137 
138  if(vals -> size() == 0) {
139  return nullptr;
140  }
141 
142  VCDSignalValues::iterator erase_until = vals->begin();
143 
144  VCDValue * tr = nullptr;
145 
146  for(auto it = vals -> begin();
147  it != vals -> end();
148  ++ it) {
149 
150  if((*it) -> time <= time) {
151  erase_until = it;
152  tr = (*it) -> value;
153  } else {
154  break;
155  }
156  }
157 
158  if (erase_prior) {
159  // avoid O(n^2) performance for large sequential scans
160  for (auto i = vals->begin() ; i != erase_until; i++) {
161  delete (*i) -> value;
162  }
163  vals->erase(vals->begin(), erase_until);
164  }
165 
166  return tr;
167 }
168 
170  VCDSignalHash hash
171 ){
172  if(this -> val_map.find(hash) == this -> val_map.end()) {
173  return nullptr;
174  }
175 
176  return this -> val_map[hash];
177 }
std::string VCDSignalHash
Compressed hash representation of a signal.
Definition: VCDTypes.hpp:23
void add_signal(VCDSignal *s)
Add a new signal to the VCD file.
Definition: VCDFile.cpp:59
std::vector< VCDScope * > * get_scopes()
Get a vector of all scopes present in the file.
Definition: VCDFile.cpp:104
std::vector< VCDTime > times
Vector of time values present in the VCD file - sorted, asc.
Definition: VCDFile.hpp:142
std::map< VCDSignalHash, VCDSignalValues * > val_map
Map of hashes onto vectors of times and signal values.
Definition: VCDFile.hpp:145
std::vector< VCDScope * > scopes
Flat mao of all scope objects in the file, keyed by name.
Definition: VCDFile.hpp:139
std::vector< VCDSignal * > * get_signals()
Return a flattened vector of all signals in the file.
Definition: VCDFile.cpp:111
Represents a single value found in a VCD File.
Definition: VCDValue.hpp:12
A signal value tagged with times.
Definition: VCDTypes.hpp:63
std::deque< VCDTimedValue * > VCDSignalValues
A vector of tagged time/value pairs, sorted by time values.
Definition: VCDTypes.hpp:70
Represents a single signal reference within a VCD file.
Definition: VCDTypes.hpp:121
VCDValue * get_signal_value_at(const VCDSignalHash &hash, VCDTime time, bool erase_prior=false)
Get the value of a particular signal at a specified time.
Definition: VCDFile.cpp:126
void add_scope(VCDScope *s)
Add a new scope object to the VCD file.
Definition: VCDFile.cpp:49
void add_timestamp(VCDTime time)
Add a new timestamp value to the VCD file.
Definition: VCDFile.cpp:118
std::vector< VCDSignal * > signals
Flat vector of all signals in the file.
Definition: VCDFile.hpp:136
~VCDFile()
Destructor.
Definition: VCDFile.cpp:13
Represents a scope type, scope name pair and all of it&#39;s child signals.
Definition: VCDTypes.hpp:133
VCDFile()
Instance a new VCD file container.
Definition: VCDFile.cpp:8
std::vector< VCDTime > * get_timestamps()
Return a pointer to the set of timestamp samples present in the VCD file.
Definition: VCDFile.cpp:97
void add_signal_value(VCDTimedValue *time_val, VCDSignalHash hash)
Add a new signal value to the VCD file, tagged by time.
Definition: VCDFile.cpp:87
VCDScope * get_scope(VCDScopeName name)
Return the scope object in the VCD file with this name.
Definition: VCDFile.cpp:74
VCDSignalValues * get_signal_values(VCDSignalHash hash)
Get a vector of VCD time values.
Definition: VCDFile.cpp:169
double VCDTime
Represents a single instant in time in a trace.
Definition: VCDTypes.hpp:26
std::string VCDScopeName
Friendly name for a scope.
Definition: VCDTypes.hpp:20