Xyce  6.1
N_DEV_InstanceName.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-------------------------------------------------------------------------
26 // Filename : $RCSfile: N_DEV_InstanceName.h,v $
27 //
28 // Purpose : Forward declarations
29 //
30 // Special Notes : Forward declaring everything as a class breaks if the implementation of the type changes (like during
31 // templatization)
32 //
33 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
34 //
35 // Creation Date : 2013/04/18 18:01:27
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.7.2.2 $
41 //
42 // Revision Date : $Date: 2015/04/02 18:29:36 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_DEV_InstanceName_h
48 #define Xyce_N_DEV_InstanceName_h
49 
50 #include <string>
51 
52 #include <N_DEV_fwd.h>
53 #include <N_UTL_NoCase.h>
54 
55 namespace Xyce {
56 namespace Device {
57 
58 //-----------------------------------------------------------------------------
59 // Class : InstanceName
60 // Purpose :
61 // Special Notes :
62 // Scope : public
63 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
64 // Creation Date : Mon May 12 15:53:34 2014
65 //-----------------------------------------------------------------------------
66 ///
67 /// Devices and models are each named. Models are not encoded, so
68 /// simple string representation is sufficient. However Devices are a
69 /// different lot. They are encoded as
70 ///
71 /// [s:]*xname
72 /// [s:]*Ytype!name
73 /// [s:]*Utype!name!count
74 ///
75 /// where s is a subcircuit name, x is a single letter device type, type
76 /// is a multiletter device type (no Y or U prefix) and count is a
77 /// special input count for the U device.
78 ///
79 /// Currently encoded names are accepted and then decoded using the
80 /// getter's. In the future, these will be stored in component form and
81 /// then encoded onyl as needed.
82 ///
84 {
85 private:
86  InstanceName(char device_letter, const std::string &device_type, const std::string &subcircuit_name, const std::string &device_name, int num_inputs)
87  : deviceLetter_(device_letter),
88  deviceType_(device_type),
89  deviceName_(device_name),
90  subcircuitName_(subcircuit_name),
91  numInputs_(num_inputs),
92  name_()
93  {
94  encode();
95  }
96 
97 public:
98  //-----------------------------------------------------------------------------
99  // Function : InstanceName
100  // Purpose :
101  // Special Notes :
102  // Scope : public
103  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
104  // Creation Date : Mon May 12 15:57:34 2014
105  //-----------------------------------------------------------------------------
106  ///
107  /// Creates an empty entity name.
108  ///
109  ///
111  : deviceLetter_(0),
112  deviceType_(),
113  deviceName_(),
114  subcircuitName_(),
115  numInputs_(0),
116  name_()
117  {}
118 
119  //-----------------------------------------------------------------------------
120  // Function : InstanceName
121  // Purpose :
122  // Special Notes :
123  // Scope : public
124  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
125  // Creation Date : Mon May 12 15:58:19 2014
126  //-----------------------------------------------------------------------------
127  ///
128  /// Creates an entity
129  ///
130  /// @invariant
131  ///
132  /// @param name model or encoded device entity name
133  ///
134  /// @return
135  ///
136  ///
137  explicit InstanceName(const std::string &name)
138  : deviceLetter_(0),
139  deviceType_(),
140  deviceName_(),
141  subcircuitName_(),
142  numInputs_(0),
143  name_(name)
144  {
145  decode();
146  }
147 
148  //-----------------------------------------------------------------------------
149  // Function : InstanceName
150  // Purpose :
151  // Special Notes :
152  // Scope : public
153  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
154  // Creation Date : Mon May 12 15:58:19 2014
155  //-----------------------------------------------------------------------------
156  ///
157  /// Copies an instance name
158  ///
159  /// @invariant
160  ///
161  /// @param name model or encoded device entity name
162  ///
163  /// @return
164  ///
165  ///
166  InstanceName(const InstanceName &entity_name)
167  : deviceLetter_(entity_name.deviceLetter_),
168  deviceType_(entity_name.deviceType_),
169  deviceName_(entity_name.deviceName_),
170  subcircuitName_(entity_name.subcircuitName_),
171  numInputs_(entity_name.numInputs_),
172  name_(entity_name.name_)
173  {}
174 
175  //-----------------------------------------------------------------------------
176  // Function : InstanceName::operator=
177  // Purpose :
178  // Special Notes :
179  // Scope : public
180  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
181  // Creation Date : Mon May 12 15:58:19 2014
182  //-----------------------------------------------------------------------------
183  ///
184  /// Assigns an instance name
185  ///
186  /// @invariant
187  ///
188  /// @param name model or encoded device entity name
189  ///
190  /// @return
191  ///
192  ///
193  InstanceName &operator=(const InstanceName &instance_name)
194  {
195  deviceLetter_ = instance_name.deviceLetter_;
196  deviceType_ = instance_name.deviceType_;
197  deviceName_ = instance_name.deviceName_;
198  subcircuitName_ = instance_name.subcircuitName_;
199  numInputs_ = instance_name.numInputs_;
200  name_ = instance_name.name_;
201 
202  return *this;
203  }
204 
205  //-----------------------------------------------------------------------------
206  // Function : getDeviceLetter
207  // Purpose :
208  // Special Notes :
209  // Scope : public
210  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
211  // Creation Date : Mon May 12 16:19:04 2014
212  //-----------------------------------------------------------------------------
213  ///
214  /// Return the first letter of the device specification after the
215  /// subcircuit.
216  ///
217  /// The device letter is Y or U for multiletter device names or the
218  /// letter that identifies the device for sinlge letter names.
219  ///
220  /// @return single letter associated with the device
221  ///
222  char getDeviceLetter() const {
223  return deviceLetter_;
224  }
225 
226  //-----------------------------------------------------------------------------
227  // Function : getDeviceType
228  // Purpose :
229  // Special Notes :
230  // Scope : public
231  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
232  // Creation Date : Mon May 12 16:02:24 2014
233  //-----------------------------------------------------------------------------
234  ///
235  /// Decodes the device type.
236  ///
237  /// The device type is a string containing the first letter for a
238  /// single letter device name, or the string starting after the Y or
239  /// U up to but noe including the exclamation point (!).
240  ///
241  /// Subcircuit prefixes are not included.
242  ///
243  /// @return string representing the device type
244  ///
245  ///
246  const std::string &getDeviceType() const {
247  return deviceType_;
248  }
249 
250 
251  //-----------------------------------------------------------------------------
252  // Function : getDeviceName
253  // Purpose :
254  // Special Notes :
255  // Scope : public
256  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
257  // Creation Date : Mon May 12 16:04:37 2014
258  //-----------------------------------------------------------------------------
259  ///
260  /// Decodes the device name.
261  ///
262  /// The device name is a string containing the first letter for a
263  /// single letter device name, or the string starting after the Y or
264  /// U up to but noe including the exclamation point (!).
265  ///
266  /// Subcircuit prefixes are not included.
267  ///
268  /// @return string representing the device name
269  ///
270  ///
271  const std::string &getDeviceName() const {
272  return deviceName_;
273  }
274 
275 
276  //-----------------------------------------------------------------------------
277  // Function : getSubcircuitName
278  // Purpose :
279  // Special Notes :
280  // Scope : public
281  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
282  // Creation Date : Mon May 12 16:04:37 2014
283  //-----------------------------------------------------------------------------
284  ///
285  /// Decodes the device name.
286  ///
287  /// The device name is a string containing the first letter for a
288  /// single letter device name, or the string starting after the Y or
289  /// U up to but noe including the exclamation point (!).
290  ///
291  /// @return string representing the device name
292  ///
293  ///
294  const std::string &getSubcircuitName() const {
295  return subcircuitName_;
296  }
297 
298 
299  //-----------------------------------------------------------------------------
300  // Function : getNumInputs
301  // Purpose :
302  // Special Notes :
303  // Scope : public
304  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
305  // Creation Date : Mon May 12 16:23:42 2014
306  //-----------------------------------------------------------------------------
307  ///
308  /// For the U device, return the number of inputs which have been
309  /// encoded into the device name. (These probably should be encoded
310  /// into the device parameters, not the name.)
311  ///
312  /// @invariant
313  ///
314  ///
315  /// @return
316  ///
317  ///
318  int getNumInputs() const {
319  return numInputs_;
320  }
321 
322  //-----------------------------------------------------------------------------
323  // Function : getEncodedName
324  // Purpose :
325  // Special Notes :
326  // Scope : public
327  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
328  // Creation Date : Mon May 19 07:40:55 2014
329  //-----------------------------------------------------------------------------
330  ///
331  /// Return the instance name encoded as:
332  /// [s:]*xname
333  /// [s:]*Ytype!name
334  /// [s:]*Utype!name!count
335  ///
336  /// @return encoded instance name
337  ///
338  ///
339  const std::string &getEncodedName() const
340  {
341  return name_;
342  }
343 
344 private:
345  void decode();
346  void encode();
347 
348  char decodeDeviceLetter() const;
349  std::string decodeDeviceType() const;
350  std::string decodeDeviceName() const;
351  std::string decodeSubcircuitName() const;
352  int decodeNumInputs() const;
353 
354 private:
355  char deviceLetter_; ///< Device letter (Y or U included)
356  std::string deviceType_; ///< Device type from netlist (does NOT include Y or U prefix)
357  std::string deviceName_; ///< Device name from netlist (subcircuit NOT included)
358  std::string subcircuitName_; ///< Device subcircuit from netlist
359  int numInputs_; ///< Hack for U type device (needs to become a parameter)
360 
361  std::string name_; ///< Complete encoded name
362 };
363 
364 inline bool operator==(const InstanceName &instance_name, const std::string &name) {
365  return equal_nocase(instance_name.getEncodedName(), name);
366 }
367 
368 inline bool operator<(const InstanceName &instance_name, const std::string &name) {
369  return less_nocase(instance_name.getEncodedName(), name);
370 }
371 
372 inline bool operator!=(const InstanceName &instance_name, const std::string &name) {
373  return !equal_nocase(instance_name.getEncodedName(), name);
374 }
375 
376 std::string setupOutputName(const InstanceName &name);
377 
378 std::ostream &operator<<(std::ostream &os, const InstanceName &instance_name);
379 
380 // void spiceInternalName(std::string &instance_name);
381 std::string spiceInternalName(const InstanceName &instance_name, const std::string &lead);
382 std::string spiceStoreName(const InstanceName &instance_name, const std::string &lead);
383 
384 } // namespace Device
385 } // namespace Xyce
386 
387 #endif // Xyce_N_DEV_InstanceName_h
388 
const std::string & getSubcircuitName() const
Decodes the device name.
Pure virtual class to augment a linear system.
Devices and models are each named.
const std::string & getEncodedName() const
Return the instance name encoded as: [s:]*xname [s:]*Ytype!name [s:]*Utype!name!count.
bool operator<(const InstanceName &instance_name, const std::string &name)
std::string decodeDeviceType() const
InstanceName(char device_letter, const std::string &device_type, const std::string &subcircuit_name, const std::string &device_name, int num_inputs)
std::string deviceName_
Device name from netlist (subcircuit NOT included)
bool operator!=(const InstanceName &instance_name, const std::string &name)
std::string decodeDeviceName() const
std::string name_
Complete encoded name.
char getDeviceLetter() const
Return the first letter of the device specification after the subcircuit.
InstanceName(const std::string &name)
Creates an entity.
std::string spiceStoreName(const InstanceName &instance_name, const std::string &lead)
InstanceName(const InstanceName &entity_name)
Copies an instance name.
InstanceName & operator=(const InstanceName &instance_name)
Assigns an instance name.
const std::string & getDeviceName() const
Decodes the device name.
std::string spiceInternalName(const InstanceName &instance_name, const std::string &lead)
bool operator==(const InstanceName &instance_name, const std::string &name)
std::string deviceType_
Device type from netlist (does NOT include Y or U prefix)
int numInputs_
Hack for U type device (needs to become a parameter)
int getNumInputs() const
For the U device, return the number of inputs which have been encoded into the device name...
const std::string & getDeviceType() const
Decodes the device type.
std::string setupOutputName(const InstanceName &name)
std::string decodeSubcircuitName() const
InstanceName()
Creates an empty entity name.
std::ostream & operator<<(std::ostream &os, const Configuration &configuration)
Definition: N_DEV_Dump.C:134
std::string subcircuitName_
Device subcircuit from netlist.
char deviceLetter_
Device letter (Y or U included)