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.10 $
41 //
42 // Revision Date : $Date: 2015/10/14 19:31:37 $
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  {
224  return deviceLetter_;
225  }
226 
227  //-----------------------------------------------------------------------------
228  // Function : getDeviceType
229  // Purpose :
230  // Special Notes :
231  // Scope : public
232  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
233  // Creation Date : Mon May 12 16:02:24 2014
234  //-----------------------------------------------------------------------------
235  ///
236  /// Decodes the device type.
237  ///
238  /// The device type is a string containing the first letter for a
239  /// single letter device name, or the string starting after the Y or
240  /// U up to but noe including the exclamation point (!).
241  ///
242  /// Subcircuit prefixes are not included.
243  ///
244  /// @return string representing the device type
245  ///
246  ///
247  const std::string &getDeviceType() const
248  {
249  return deviceType_;
250  }
251 
252 
253  //-----------------------------------------------------------------------------
254  // Function : getDeviceName
255  // Purpose :
256  // Special Notes :
257  // Scope : public
258  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
259  // Creation Date : Mon May 12 16:04:37 2014
260  //-----------------------------------------------------------------------------
261  ///
262  /// Decodes the device name.
263  ///
264  /// The device name is a string containing the first letter for a
265  /// single letter device name, or the string starting after the Y or
266  /// U up to but noe including the exclamation point (!).
267  ///
268  /// Subcircuit prefixes are not included.
269  ///
270  /// @return string representing the device name
271  ///
272  ///
273  const std::string &getDeviceName() const
274  {
275  return deviceName_;
276  }
277 
278 
279  //-----------------------------------------------------------------------------
280  // Function : getSubcircuitName
281  // Purpose :
282  // Special Notes :
283  // Scope : public
284  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
285  // Creation Date : Mon May 12 16:04:37 2014
286  //-----------------------------------------------------------------------------
287  ///
288  /// Decodes the device name.
289  ///
290  /// The device name is a string containing the first letter for a
291  /// single letter device name, or the string starting after the Y or
292  /// U up to but noe including the exclamation point (!).
293  ///
294  /// @return string representing the device name
295  ///
296  ///
297  const std::string &getSubcircuitName() const
298  {
299  return subcircuitName_;
300  }
301 
302 
303  //-----------------------------------------------------------------------------
304  // Function : getNumInputs
305  // Purpose :
306  // Special Notes :
307  // Scope : public
308  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
309  // Creation Date : Mon May 12 16:23:42 2014
310  //-----------------------------------------------------------------------------
311  ///
312  /// For the U device, return the number of inputs which have been
313  /// encoded into the device name. (These probably should be encoded
314  /// into the device parameters, not the name.)
315  ///
316  /// @invariant
317  ///
318  ///
319  /// @return
320  ///
321  ///
322  int getNumInputs() const
323  {
324  return numInputs_;
325  }
326 
327  //-----------------------------------------------------------------------------
328  // Function : getEncodedName
329  // Purpose :
330  // Special Notes :
331  // Scope : public
332  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
333  // Creation Date : Mon May 19 07:40:55 2014
334  //-----------------------------------------------------------------------------
335  ///
336  /// Return the instance name encoded as:
337  /// [s:]*xname
338  /// [s:]*Ytype!name
339  /// [s:]*Utype!name!count
340  ///
341  /// @return encoded instance name
342  ///
343  ///
344  const std::string &getEncodedName() const
345  {
346  return name_;
347  }
348 
349 private:
350  void decode();
351  void encode();
352 
353  char decodeDeviceLetter() const;
354  std::string decodeDeviceType() const;
355  std::string decodeDeviceName() const;
356  std::string decodeSubcircuitName() const;
357  int decodeNumInputs() const;
358 
359 private:
360  char deviceLetter_; ///< Device letter (Y or U included)
361  std::string deviceType_; ///< Device type from netlist (does NOT include Y or U prefix)
362  std::string deviceName_; ///< Device name from netlist (subcircuit NOT included)
363  std::string subcircuitName_; ///< Device subcircuit from netlist
364  int numInputs_; ///< Hack for U type device (needs to become a parameter)
365 
366  std::string name_; ///< Complete encoded name
367 };
368 
369 inline bool operator==(const InstanceName &instance_name, const std::string &name)
370 {
371  return equal_nocase(instance_name.getEncodedName(), name);
372 }
373 
374 inline bool operator<(const InstanceName &instance_name, const std::string &name)
375 {
376  return less_nocase(instance_name.getEncodedName(), name);
377 }
378 
379 inline bool operator!=(const InstanceName &instance_name, const std::string &name)
380 {
381  return !equal_nocase(instance_name.getEncodedName(), name);
382 }
383 
384 std::string setupOutputName(const InstanceName &name);
385 
386 std::ostream &operator<<(std::ostream &os, const InstanceName &instance_name);
387 
388 // void spiceInternalName(std::string &instance_name);
389 std::string spiceInternalName(const InstanceName &instance_name, const std::string &lead);
390 std::string spiceStoreName(const InstanceName &instance_name, const std::string &lead);
391 
392 } // namespace Device
393 } // namespace Xyce
394 
395 #endif // Xyce_N_DEV_InstanceName_h
396 
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)