Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2011 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.3 $
41 //
42 // Revision Date : $Date: 2014/05/19 20:00:59 $
43 //
44 // Current Owner : $Author: dgbaur $
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 subciruit 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  subcircuitName_(subcircuit_name),
90  deviceName_(device_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  subcircuitName_(),
114  deviceName_(),
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  /// Creates an entity
158  ///
159  /// @invariant
160  ///
161  /// @param name model or encoded device entity name
162  ///
163  /// @return
164  ///
165  ///
166  InstanceName &operator=(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  return *this;
174  }
175 
176  //-----------------------------------------------------------------------------
177  // Function : getDeviceLetter
178  // Purpose :
179  // Special Notes :
180  // Scope : public
181  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
182  // Creation Date : Mon May 12 16:19:04 2014
183  //-----------------------------------------------------------------------------
184  ///
185  /// Return the first letter of the device specification after the
186  /// subcircuit.
187  ///
188  /// The device letter is Y or U for multiletter device names or the
189  /// letter that identifies the device for sinlge letter names.
190  ///
191  /// @return single letter associated with the device
192  ///
193  char getDeviceLetter() const {
194  return deviceLetter_;
195  }
196 
197  //-----------------------------------------------------------------------------
198  // Function : getDeviceType
199  // Purpose :
200  // Special Notes :
201  // Scope : public
202  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
203  // Creation Date : Mon May 12 16:02:24 2014
204  //-----------------------------------------------------------------------------
205  ///
206  /// Decodes the device type.
207  ///
208  /// The device type is a string containing the first letter for a
209  /// single letter device name, or the string starting after the Y or
210  /// U up to but noe including the exclamation point (!).
211  ///
212  /// Subcircuit prefixes are not included.
213  ///
214  /// @return string representing the device type
215  ///
216  ///
217  std::string getDeviceType() const {
218  return deviceType_;
219  }
220 
221 
222  //-----------------------------------------------------------------------------
223  // Function : getDeviceName
224  // Purpose :
225  // Special Notes :
226  // Scope : public
227  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
228  // Creation Date : Mon May 12 16:04:37 2014
229  //-----------------------------------------------------------------------------
230  ///
231  /// Decodes the device name.
232  ///
233  /// The device name is a string containing the first letter for a
234  /// single letter device name, or the string starting after the Y or
235  /// U up to but noe including the exclamation point (!).
236  ///
237  /// Subcircuit prefixes are not included.
238  ///
239  /// @return string representing the device name
240  ///
241  ///
242  std::string getDeviceName() const {
243  return deviceName_;
244  }
245 
246 
247  //-----------------------------------------------------------------------------
248  // Function : getDeviceName
249  // Purpose :
250  // Special Notes :
251  // Scope : public
252  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
253  // Creation Date : Mon May 12 16:04:37 2014
254  //-----------------------------------------------------------------------------
255  ///
256  /// Decodes the device name.
257  ///
258  /// The device name is a string containing the first letter for a
259  /// single letter device name, or the string starting after the Y or
260  /// U up to but noe including the exclamation point (!).
261  ///
262  /// @return string representing the device name
263  ///
264  ///
265  std::string getSubcircuitName() const {
266  return subcircuitName_;
267  }
268 
269 
270  //-----------------------------------------------------------------------------
271  // Function : getNumInputs
272  // Purpose :
273  // Special Notes :
274  // Scope : public
275  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
276  // Creation Date : Mon May 12 16:23:42 2014
277  //-----------------------------------------------------------------------------
278  ///
279  /// For the U device, return the number of inputs which have been
280  /// encoded into the device name. (These probably should be encoded
281  /// into the device parameters, not the name.)
282  ///
283  /// @invariant
284  ///
285  ///
286  /// @return
287  ///
288  ///
289  int getNumInputs() const {
290  return numInputs_;
291  }
292 
293  //-----------------------------------------------------------------------------
294  // Function : getEncodedName
295  // Purpose :
296  // Special Notes :
297  // Scope : public
298  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
299  // Creation Date : Mon May 19 07:40:55 2014
300  //-----------------------------------------------------------------------------
301  ///
302  /// Return the instance name encoded as:
303  /// [s:]*xname
304  /// [s:]*Ytype!name
305  /// [s:]*Utype!name!count
306  ///
307  /// @return encoded instance name
308  ///
309  ///
310  const std::string &getEncodedName() const
311  {
312  return name_;
313  }
314 
315 private:
316  void decode();
317  void encode();
318 
319  char decodeDeviceLetter() const;
320  std::string decodeDeviceType() const;
321  std::string decodeDeviceName() const;
322  std::string decodeSubcircuitName() const;
323  int decodeNumInputs() const;
324 
325 private:
326  char deviceLetter_; ///< Device letter (Y or U included)
327  std::string deviceType_; ///< Device type from netlist (does NOT include Y or U prefix)
328  std::string deviceName_; ///< Device name from netlist (subcircuit NOT included)
329  std::string subcircuitName_; ///< Device subcircuit from netlist
330  int numInputs_; ///< Hack for U type device (needs to become a parameter)
331 
332  std::string name_; ///< Complete encoded name
333 };
334 
335 inline bool operator==(const InstanceName &entity_name, const std::string &name) {
336  return equal_nocase(entity_name.getEncodedName(), name);
337 }
338 
339 inline bool operator<(const InstanceName &entity_name, const std::string &name) {
340  return less_nocase(entity_name.getEncodedName(), name);
341 }
342 
343 inline bool operator!=(const InstanceName &entity_name, const std::string &name) {
344  return !equal_nocase(entity_name.getEncodedName(), name);
345 }
346 
347 std::string setupOutputName(const InstanceName &name);
348 
349 std::ostream &operator<<(std::ostream &os, const InstanceName &entity_name);
350 
351 void spiceInternalName(std::string &entity_name);
352 std::string spiceInternalName(const InstanceName &entity_name, const std::string &lead);
353 std::string spiceStoreName(const InstanceName &entity_name, const std::string &lead);
354 
355 } // namespace Device
356 } // namespace Xyce
357 
358 #endif // Xyce_N_DEV_InstanceName_h
359