Blame view

GUI/SW2/SRC/src/netlist/Component.cpp 25.7 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
//**************************************************************************************************
//                                          Component.cpp                                          *
//                                         ---------------                                         *
// Started     : 2004-05-14                                                                        *
// Last Update : 2016-10-23                                                                        *
// Copyright   : (C) 2004-2016 MSWaters                                                            *
//**************************************************************************************************

//**************************************************************************************************
//                                                                                                 *
//      This program is free software; you can redistribute it and/or modify it under the          *
//      terms of the GNU General Public License as published by the Free Software Foundation;      *
//      either version 3 of the License, or (at your option) any later version.                    *
//                                                                                                 *
//**************************************************************************************************

#include "Component.hpp"

//**************************************************************************************************
// Finish the definition of the ArrayComponent type. The following expands into
// some C++ code and so should only be compiled once (ie. don't put this into a
// header file rather put it in a source file or there will be linker errors).

#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY( ArrayComponent );

//**************************************************************************************************
// Constructor.

Component::Component( void ) : wxString( )
{
  bClear( );
}

//**************************************************************************************************
// Destructor.

Component::~Component( )
{
}

//**************************************************************************************************
// Get the component ports.

void  Component::GetPorts( void )
{
  // Not yet implemented ???
}

//**************************************************************************************************
// Test the values against each other.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bValidate( void )
{
  m_osErrMsg.Empty( );

  if( IsEmpty( ) )                      bSetErrMsg( wxT("component is empty") );
  else if( m_osName.IsEmpty( ) )        bSetErrMsg( wxT("component has no name") );
  else if( m_osaNodes.GetCount( ) < 2 ) bSetErrMsg( wxT("component has less than two nodes") );
  else if( m_osValue.IsEmpty( ) )       bSetErrMsg( wxT("component has no value") );

  return( bIsValid( ) );
}

//**************************************************************************************************
// Attempt to set the objects error message string attribute.
//
// Argument List :
//   rosErrMsg - A reference to a string containing the new error message
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bSetErrMsg( const wxString & rosErrMsg )
{
  if( ! bIsValid( ) ) return( false );

  m_osErrMsg = rosErrMsg;

  return( true );
}

//**************************************************************************************************
// Compare algorithm for sorting Component objects.
//
// Argument List :
//   ppo1 - The address of a pointer to the first  Component object to compare
//   ppo2 - The address of a pointer to the second Component object to compare
//
// Return Values :
//   >0 - If *(*ppo1) is greater than *(*ppo2)
//   =0 - If *(*ppo1) is equal to     *(*ppo2)
//   <0 - If *(*ppo1) is less    than *(*ppo2)

int  Component::iCompare( Component ** ppo1, Component ** ppo2 )
{
  const wxString & ros1 = (const wxString &) **ppo1;
  const wxString & ros2 = (const wxString &) **ppo2;

  return( ros1.Cmp( ros2 ) );
}

//**************************************************************************************************
// Clear the object attributes.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bClear( void )
{
  wxString::Empty( );

  m_osErrMsg = wxT("Invalid");

  m_osName  .Clear( );
  m_osaNodes.Clear( );
  m_osValue .Clear( );

  m_eType = eCPNT_NONE;
  m_osaPorts.Clear( );

  return( true );
}

//**************************************************************************************************
// Parse a component definition string extracted from a netlist.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bParse( void )
{
  wxStringTokenizer  ostk1;
  wxString           os1;
  size_t             sz1;

  // Clear the object attributes
  os1 = (wxString &) *this;
  bClear( );
  wxString::assign( os1 );
  m_osErrMsg.Empty( );

  // Tokenize the command string
  if( IsEmpty( ) )               return( bValidate( ) );
  ostk1.SetString( os1 );

  // Extract the component name
  bSetName( ostk1.GetNextToken( ) );

  // Extract the nodes the component is connected to
  if( ! ostk1.HasMoreTokens( ) ) return( bValidate( ) );
  bSetNodes( ostk1.GetString( ) );
  for( sz1=0; sz1<m_osaNodes.GetCount( ); sz1++ )
    ostk1.GetNextToken( );

  // Extract the component value
  if( ! ostk1.HasMoreTokens( ) ) return( bValidate( ) );
  bSetValue( ostk1.GetString( ) );

  return( bValidate( ) );
}

//**************************************************************************************************
// Format the command string.
//
// Eg. : C1 6 2 100n
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bFormat( void )
{
  wxString  osCmd;
  size_t    sz1;

  // Format the value part of the component definition
  bFormatValue( );

  // Set the name
  osCmd = m_osName;

  // Append the nodes
  for( sz1=0; sz1<m_osaNodes.GetCount( ); sz1++ )
    osCmd << wxT(' ') << m_osaNodes.Item( sz1 );

  // Append the value
  osCmd << wxT(' ') << m_osValue;

  wxString::assign( osCmd );

  return( bValidate( ) );
}

//**************************************************************************************************
// Set the object attributes via a component definition string.
//
// Argument List :
//   rosCmd - A reference to a string containing a component definition
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bSetString( const wxString & rosCmd )
{
  // Clear the component attributes
  bClear( );

  // Set the underlying string to the raw component definition
  wxString::assign( rosTrim( rosCmd ) );

  // Parse the component definition
  bParse( );

  return( bIsValid( ) );
}

//**************************************************************************************************
// Set the component name.
//
// Argument List :
//   rosName - A reference to a string containing a compoent name
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bSetName( const wxString & rosName )
{
  wxStringTokenizer  ostk1;
  wxString           os1;
  wxChar             oc1;

  // Tokenize the name string
  ostk1.SetString( rosName );
  if( ostk1.CountTokens( ) <=0 )                                               return( false );

  // Extract the component name and check that it begins with an alpha character
  os1 = ostk1.GetNextToken( );
  oc1 = os1.GetChar( 0 );
  if( !(oc1>=wxT('a') && oc1<=wxT('z')) && !(oc1>=wxT('A') && oc1<=wxT('Z')) ) return( false );
  m_osName = os1;

  // Determine the component type and units type
  m_eType = eGetType( m_osName );

  return( true );
}

//**************************************************************************************************
// Set the component nodes.
//
// Argument List :
//   rosNodes - A reference to a string containing component nodes eg. "2,1".
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bSetNodes( const wxString & rosNodes )
{
  wxStringTokenizer  ostk1;
  size_t             szNodeCnt;
  size_t             sz1;

  // Tokenize the name string
  ostk1.SetString( rosNodes, wxT(" \t\r\n,") );
  if( ostk1.CountTokens( ) <=0 )         return( false );

  // Determine how many nodes to look for based on the component type
  switch( m_eType )
  {
    case eCPNT_CAP    :
    case eCPNT_RES    :
    case eCPNT_IND    :
    case eCPNT_CIND   :
    case eCPNT_DIODE  :
    case eCPNT_VCVS   :
    case eCPNT_CCCS   :
    case eCPNT_VCCS   :
    case eCPNT_CCVS   :
    case eCPNT_IVS    :
    case eCPNT_ICS    :
    case eCPNT_NLDS   :
    case eCPNT_NLDCS  :
    case eCPNT_NLDVS  :
    case eCPNT_STJ    : szNodeCnt = 2;                        break;

    case eCPNT_JFET   :
    case eCPNT_MOSFET :
    case eCPNT_MESFET :
    case eCPNT_BJT    :
    case eCPNT_VCSW   :
    case eCPNT_CCSW   :
    case eCPNT_URC    : szNodeCnt = 3;                        break;

    case eCPNT_TLINE  :
    case eCPNT_LTRA   :
    case eCPNT_TXL    : szNodeCnt = 4;                        break;

    case eCPNT_LOGIC  : szNodeCnt = ostk1.CountTokens( ) - 2; break;

    case eCPNT_CPL    :
    case eCPNT_SUBCKT : szNodeCnt = ostk1.CountTokens( ) - 1; break;

    // For the default guess that all but the last token are nodes
    default           : szNodeCnt = ostk1.CountTokens( ) - 1; break;
  }
  if( szNodeCnt > ostk1.CountTokens( ) ) return( false );

  // Extract the nodes the component is connected to
  m_osaNodes.Empty( );
  if( szNodeCnt > 0 )
  {
    for( sz1=0; sz1<szNodeCnt; sz1++ )
      m_osaNodes.Add( ostk1.GetNextToken( ) );
  }
  else
  {
    for( sz1=0; sz1<ostk1.CountTokens( ); sz1++ )
    {
      if( isalpha( ostk1.GetString( ).GetChar( 0 ) ) ) break;
      m_osaNodes.Add( ostk1.GetNextToken( ) );
    }
  }

  // Determine the device ports
  GetPorts( );

  return( true );
}

//**************************************************************************************************
// Set the component value.
//
// Argument List :
//   rosName - A reference to a string containing a compoent value
//
// Return Values :
//   true  - Success
//   false - Failure

bool  Component::bSetValue( const wxString & rosValue )
{
  wxString  os1;

  // Check if the string is empty
  os1 = rosTrim( rosValue );
  if( os1.IsEmpty( ) ) return( false );

  // Extract the component value
  m_osValue = os1;

  return( bParseValue( ) );
}

//**************************************************************************************************
// Get the component definition string.
//
// Return Values :
//   A reference to the component definition string

const wxString & Component::rosGetString( void )
{
  bFormat( );

  return( (wxString &) *this );
}

//**************************************************************************************************
// Get the component nodes as a string separated by a comma.
//
// Return Values :
//   A reference to the component nodes string

const wxString & Component::rosGetNodes( void )
{
  static  wxString  osNodes;
          size_t    sz1;

  osNodes.Empty( );

  if( ! m_osaNodes.IsEmpty( ) )
  {
    for( sz1=0; sz1<m_osaNodes.GetCount( ); sz1++ )
    {
      if( ! osNodes.IsEmpty( ) ) osNodes << wxT(",");
      osNodes << m_osaNodes.Item( sz1 );
    }
  }

  return( osNodes );
}

//**************************************************************************************************
// Get the numeric value as a mantissa and exponent if possible.
//
// Return Values :
//   A reference to the component nodes string

const wxString & Component::rosGetNumValue( void )
{
  static  wxString   osNumValue;
  wxStringTokenizer  ostk1;
  wxString           os1;

  // Clear the local static variable
  osNumValue.Empty( );

  // Tokenize the value string
  ostk1.SetString( m_osValue );

  // Attempt to parse a field in the value string as a numeric quantity
  while( ostk1.HasMoreTokens( ) )
  {
    os1 = ostk1.GetNextToken( );

    if(      CnvtType::bIsInteger( os1 ) )
    {
      osNumValue = os1;
      break;
    }
    else if( CnvtType::bIsFloat( os1 ) )
    {
      osNumValue = os1;
      break;
    }
  }

  return( osNumValue );
}

//**************************************************************************************************
// Get the component type.
//
// Argument List :
//   rosName - A component name
//
// Return Values :
//   An enumerate type indicating the type of the component

eTypeCpnt  Component::eGetType( const wxString & rosName )
{
  // Determine the component type from the first character of the name
  switch( toupper( rosName.GetChar( 0 ) ) )
  {
    case wxT('B') : return( eCPNT_NLDS   );
    case wxT('C') : return( eCPNT_CAP    );
    case wxT('D') : return( eCPNT_DIODE  );
    case wxT('E') : return( eCPNT_VCVS   );
    case wxT('F') : return( eCPNT_CCCS   );
    case wxT('G') : return( eCPNT_VCCS   );
    case wxT('H') : return( eCPNT_CCVS   );
    case wxT('I') : return( eCPNT_ICS    );
    case wxT('J') : return( eCPNT_JFET   );
    case wxT('K') : return( eCPNT_CIND   );
    case wxT('L') : return( eCPNT_IND    );
    case wxT('M') : return( eCPNT_MOSFET );
    case wxT('O') : return( eCPNT_LTRA   );
    case wxT('P') : return( eCPNT_CPL    );
    case wxT('Q') : return( eCPNT_BJT    );
    case wxT('R') : return( eCPNT_RES    );
    case wxT('S') : return( eCPNT_VCSW   );
    case wxT('T') : return( eCPNT_TLINE  );
    case wxT('U') : return( eCPNT_URC    );
    case wxT('V') : return( eCPNT_IVS    );
    case wxT('W') : return( eCPNT_CCSW   );
    case wxT('X') : return( eCPNT_SUBCKT );
    case wxT('Y') : return( eCPNT_TXL    );
    case wxT('Z') : return( eCPNT_MESFET );

    default       : return( eCPNT_NONE   );
  }
}

//**************************************************************************************************
// Get the units type (where appropriate).
//
// Argument List :
//   rosName - A component name
//
// Return Values :
//   An enumerate type indicating the type of units associated with this component

eTypeUnits  Component::eGetUnitsType( const wxString & rosName )
{
  // Determine the units type from the first character of the name
  switch( toupper( rosName.GetChar( 0 ) ) )
  {
    case wxT('B') : return( eUNITS_EXP  );
    case wxT('C') : return( eUNITS_CAP  );
    case wxT('D') : return( eUNITS_NONE );
    case wxT('E') : return( eUNITS_EXP  );
    case wxT('F') : return( eUNITS_EXP  );
    case wxT('G') : return( eUNITS_EXP  );
    case wxT('H') : return( eUNITS_EXP  );
    case wxT('I') : return( eUNITS_CURR );
    case wxT('J') : return( eUNITS_NONE );
    case wxT('K') : return( eUNITS_IND  );
    case wxT('L') : return( eUNITS_IND  );
    case wxT('M') : return( eUNITS_NONE );
    case wxT('Q') : return( eUNITS_NONE );
    case wxT('R') : return( eUNITS_RES  );
    case wxT('S') : return( eUNITS_NONE );
    case wxT('T') : return( eUNITS_NONE );
    case wxT('U') : return( eUNITS_NONE );
    case wxT('V') : return( eUNITS_VOLT );
    case wxT('W') : return( eUNITS_NONE );
    case wxT('X') : return( eUNITS_NONE );
    case wxT('Y') : return( eUNITS_RES  );

    default       : return( eUNITS_NONE );
  }
}

//**************************************************************************************************
// Trim a component definition string by replacing all field separaters with a single space
// character and removing any line terminators.
//
// Argument List :
//   rosDefn - A reference to a string containing a component definition
//
// Return Values :
//   A reference to a string containing a trimmed copy of the component defn

const wxString & Component::rosTrim( const wxString & rosDefn )
{
  static  wxString   osDefn;
  wxStringTokenizer  ostk1;

  // Tokenize the component definition
  ostk1.SetString( rosDefn, wxT(" \t\r\n"), wxTOKEN_STRTOK );

  // Reconstruct the component definition
  osDefn = ostk1.GetNextToken( );
  while( ostk1.HasMoreTokens( ) )
    osDefn << wxT(' ') << ostk1.GetNextToken( );

  return( osDefn );
}

//**************************************************************************************************
// Copy the contents of a wxString object.
//
// Argument List :
//   rosCmd - A reference to a string containing a component definition
//
// Return Values :
//   A reference to this object

wxString & Component::operator = ( const wxString & rosCmd )
{
  bSetString( rosCmd );

  return( *((wxString *) this) );
}

//**************************************************************************************************
// Copy the contents of another Component object.
//
// Argument List :
//   roCpnt - A reference to a Component object
//
// Return Values :
//   A reference to this object

Component & Component::operator = ( const Component & roCpnt )
{
  (wxString &) *this = (wxString &) roCpnt;

  m_eType    = roCpnt.m_eType;

  m_osName   = roCpnt.m_osName;
  m_osaNodes = roCpnt.m_osaNodes;
  m_osValue  = roCpnt.m_osValue;

  m_osaPorts = roCpnt.m_osaPorts;

  m_osErrMsg = roCpnt.m_osErrMsg;

  return( *this );
}

//**************************************************************************************************
// Print the object attributes.
//
// Argument List :
//   rosPrefix - A prefix to every line displayed (usually just spaces)

void  Component::Print( const wxString & rosPrefix )
{
  size_t  sz1;

  std::cout << rosPrefix.mb_str( ) << "wxString::        : " << this            ->mb_str( ) << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osErrMsg        : " << m_osErrMsg       .mb_str( ) << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_eType           : ";
  switch( m_eType )
  {
    case eCPNT_CAP    : std::cout << "eCPNT_CAP"   ; break; // Capacitor
    case eCPNT_RES    : std::cout << "eCPNT_RES"   ; break; // Resistor
    case eCPNT_IND    : std::cout << "eCPNT_IND"   ; break; // Inductor
    case eCPNT_CIND   : std::cout << "eCPNT_CIND"  ; break; // Coupled (Mutual) Inductors
    case eCPNT_DIODE  : std::cout << "eCPNT_DIODE" ; break; // Diode
    case eCPNT_BJT    : std::cout << "eCPNT_BJT"   ; break; // BJT (Bipolar Junction Transistor)
    case eCPNT_JFET   : std::cout << "eCPNT_JFET"  ; break; // JFET (Junction Field-Effect Transistor)
    case eCPNT_MOSFET : std::cout << "eCPNT_MOSFET"; break; // MOSFET (Metal-Oxide Semiconductor Field-Effect Transistor)
    case eCPNT_MESFET : std::cout << "eCPNT_MESFET"; break; // MESFET (Metal–Semiconductor Field Effect Transistor)
    case eCPNT_VCVS   : std::cout << "eCPNT_VCVS"  ; break; // Voltage Controlled Voltage Source
    case eCPNT_CCCS   : std::cout << "eCPNT_CCCS"  ; break; // Current Controlled Current Source
    case eCPNT_VCCS   : std::cout << "eCPNT_VCCS"  ; break; // Voltage Controlled Current Source
    case eCPNT_CCVS   : std::cout << "eCPNT_CCVS"  ; break; // Current Controlled Voltage Source
    case eCPNT_TLINE  : std::cout << "eCPNT_TLINE" ; break; // Lossless Transmission Line
    case eCPNT_LTRA   : std::cout << "eCPNT_LTRA"  ; break; // Lossy Transmission Line (LTRA)
    case eCPNT_CPL    : std::cout << "eCPNT_CPL"   ; break; // Coupled Multi-conductor Transmission Line (CPL)
    case eCPNT_TXL    : std::cout << "eCPNT_TXL"   ; break; // Single Lossy Transmission Line (TXL)
    case eCPNT_URC    : std::cout << "eCPNT_URC"   ; break; // Uniform Distributed RC Transmission Line (URC)
    case eCPNT_ICS    : std::cout << "eCPNT_ICS"   ; break; // Independent Current Source
    case eCPNT_IVS    : std::cout << "eCPNT_IVS"   ; break; // Independent Voltage Source
    case eCPNT_NLDS   : std::cout << "eCPNT_NLDS"  ; break; // Non-Linear Dependent Source
    case eCPNT_NLDCS  : std::cout << "eCPNT_NLDCS" ; break; // Non-Linear Dependent Current Source
    case eCPNT_NLDVS  : std::cout << "eCPNT_NLDVS" ; break; // Non-Linear Dependent Voltage Source
    case eCPNT_CCSW   : std::cout << "eCPNT_CCSW"  ; break; // Current Controlled Switch
    case eCPNT_VCSW   : std::cout << "eCPNT_VCSW"  ; break; // Voltage Controlled Switch
    case eCPNT_SUBCKT : std::cout << "eCPNT_SUBCKT"; break; // Sub-circuit
    case eCPNT_LOGIC  : std::cout << "eCPNT_LOGIC" ; break; // Logic Device
    case eCPNT_STJ    : std::cout << "eCPNT_STJ"   ; break; // Super-conducting Tunnel Junction

    default           : std::cout << "Invalid";
  }
  std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osName          : " << m_osName         .mb_str( ) << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osaNodes[ ]     : ";
  for( sz1=0; sz1<m_osaNodes.GetCount( ); sz1++ )
  {
    if( sz1 > 0 ) std::cout << ", ";
    std::cout << m_osaNodes.Item( sz1 ).mb_str( );
  }
  std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osaPorts[ ]     : ";
  for( sz1=0; sz1<m_osaPorts.GetCount( ); sz1++ )
  {
    if( sz1 > 0 ) std::cout << " ";
    std::cout << m_osaPorts.Item( sz1 ).mb_str( );
  }
  std::cout << '\n';

  std::cout << rosPrefix.mb_str( ) << "m_osValue         : " << m_osValue        .mb_str( ) << '\n';

  std::cout << rosPrefix.mb_str( ) << "rosGetNumValue( ) : " << rosGetNumValue( ).mb_str( ) << '\n';

  std::cout << rosPrefix.mb_str( ) << "eGetUnitsType( )  : ";
  switch( eGetUnitsType( m_osName ) )
  {
    case eUNITS_CAP  : std::cout << "eUNITS_CAP";  break;
    case eUNITS_IND  : std::cout << "eUNITS_IND";  break;
    case eUNITS_RES  : std::cout << "eUNITS_RES";  break;
    case eUNITS_VOLT : std::cout << "eUNITS_VOLT"; break;
    case eUNITS_CURR : std::cout << "eUNITS_CURR"; break;
    case eUNITS_TIME : std::cout << "eUNITS_TIME"; break;
    case eUNITS_FREQ : std::cout << "eUNITS_FREQ"; break;
    case eUNITS_PHAD : std::cout << "eUNITS_PHAD"; break;
    case eUNITS_PHAR : std::cout << "eUNITS_PHAR"; break;
    case eUNITS_TMPC : std::cout << "eUNITS_TMPC"; break;
    case eUNITS_TMPF : std::cout << "eUNITS_TMPF"; break;
    case eUNITS_EXP  : std::cout << "eUNITS_EXP";  break;
    case eUNITS_NONE : std::cout << "eUNITS_NONE"; break;

    default          : std::cout << "Invalid";     break;
  }
  std::cout << '\n';
}

//**************************************************************************************************
//                                          Test Utility                                           *
//**************************************************************************************************

#ifdef TEST_COMPONENT

using  namespace  std;

// Function prototypes

void  Usage( char * psAppName );

//**************************************************************************************************

int  main( int argc, char * argv[ ] )
{
  // This function is used in wxBase only and only if an wxApp object isn't created at all. In this
  // case wxInitialize( ) must be called in main( ) before calling any other wxWidgets functions.
  if( ! wxInitialize( ) ) exit( EXIT_FAILURE );

  wxString  osCpnt;
  wxString  os1;

  // Validate the argument count passed to the application
  if( argc > 2 )                    { Usage( argv[ 0 ] ); exit( EXIT_FAILURE ); }

  // Process the command line arguments
  if( argc > 1 )
  {
    os1 = wxConvLibc.cMB2WC( argv[ 1 ] );
    if( os1.at( 0 ) == wxT('-') )
    {
      if( os1.at( 1 ) == wxT('h') ) { Usage( argv[ 0 ] ); exit( EXIT_SUCCESS ); }
      else                          { Usage( argv[ 0 ] ); exit( EXIT_FAILURE ); }
    }
  }
  else                              { Usage( argv[ 0 ] ); exit( EXIT_FAILURE ); }

  // Display the utility banner
  cout << "\n  Component Class Test Utility"
       << "\n   Version 1.09 (2016-09-29)\n";

  // Create a component object
  Component  oCpnt;

  // Use the following command example to check the formatter and the parser :
  osCpnt = wxT("Vin	 2	0	 AC 1V");  // This definition does contain TABs and SPACEs
  cout << "\nCpnt defn to test : "
       << osCpnt.mb_str( ) << "\n\n";

  // ******************** Test the formatter ********************
  cout << "Test the component formatter :";

  // Set things up for a formatter test
  oCpnt.bClear( );
  oCpnt.bSetName ( wxT("Vin")   );
  oCpnt.bSetNodes( wxT("2,0")   );
  oCpnt.bSetValue( wxT("AC 1V") );

  // Run the formatter
  cout << "\n  Run formatter  : ";
  if( oCpnt.bFormat( ) )
       cout << "OK";
  else cout << "FAULT (" << oCpnt.rosGetErrMsg( ).mb_str( ) << ')';

  // Test the formatter output
  cout << "\n  Test format    : ";
  if( (wxString) oCpnt == Component::rosTrim( osCpnt ) )
    cout << "OK\n" << "  Component defn : "
         << oCpnt.rosGetString( ).mb_str( ) << '\n';
  else
  { // There's been an error so print the component contents
    cout << "FAULT\n";
    cout << "  oCpnt Contents : \n";
    oCpnt.Print( wxT("    ") );
  }

  cout << "\n";

  // ********************* Test the parser *********************
  cout << "Test the component parser :";

  // Set things up for a parser test
  oCpnt.bClear( );
  oCpnt = osCpnt;

  // Run the parser
  cout << "\n  Run parser     : ";
  if( oCpnt.bParse( ) )
       cout << "OK";
  else cout << "FAULT (" << oCpnt.rosGetErrMsg( ).mb_str( ) << ')';

  // Test the parser output
  oCpnt.bFormat( );
  cout << "\n  Test format    : ";
  if( (wxString) oCpnt == Component::rosTrim( osCpnt ) )
    cout << "OK\n" << "  Component defn : "
         << oCpnt.rosGetString( ).mb_str( ) << '\n';
  else
  { // There's been an error so print the component contents
    cout << "FAULT\n";
    cout << "  oCpnt Contents : \n";
    oCpnt.Print( wxT("    ") );
  }

  cout << "\n";

  // This function must be called for each successful call to wxInitialize( ). Clean up; the library
  // can't be used any more.
  wxInitialize( );

  exit( EXIT_SUCCESS );
}

//**************************************************************************************************

void  Usage( char * psAppName )
{
  cout << "\nUsage   : " << psAppName << " [-OPTIONS] [CPNTDEF]"
       << "\nOptions : -h      : Print usage (this message)"
       << "\n          CPNTDEF : An component definition (not yet implemented)"
       << "\n\n";
}

#endif // TEST_COMPONENT

//**************************************************************************************************