This file is indexed.

/usr/include/omniORB4/internal/typecode.h is in libomniorb4-dev 4.1.6-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
// -*- Mode: C++; -*-
//                            Package   : omniORB
// typecode.h                 Created on: 03/09/98
//                            Author1   : James Weatherall (jnw)
//                            Author2   : David Riddoch (djr)
//                            Author3   : Duncan Grisby (dgrisby)
//
//    Copyright (C) 2004-2006 Apasphere Ltd.
//    Copyright (C) 1996-1999 AT&T Laboratories Cambridge
//
//    This file is part of the omniORB library
//
//    The omniORB library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Library General Public
//    License as published by the Free Software Foundation; either
//    version 2 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Library General Public License for more details.
//
//    You should have received a copy of the GNU Library General Public
//    License along with this library; if not, write to the Free
//    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
//    02111-1307, USA
//
//
// Description:
//   Internal typecode classes.
//

/*
 * $Log$
 * Revision 1.1.4.5  2006/11/28 00:09:42  dgrisby
 * TypeCode collector could access deleted data when freeing TypeCodes
 * with multiple loops.
 *
 * Revision 1.1.4.4  2006/05/20 16:23:37  dgrisby
 * Minor cdrMemoryStream and TypeCode performance tweaks.
 *
 * Revision 1.1.4.3  2004/05/25 14:20:50  dgrisby
 * ValueType TypeCode support.
 *
 * Revision 1.1.4.2  2004/04/02 13:26:24  dgrisby
 * Start refactoring TypeCode to support value TypeCodes, start of
 * abstract interfaces support.
 *
 * Revision 1.1.4.1  2003/03/23 21:03:42  dgrisby
 * Start of omniORB 4.1.x development branch.
 *
 * Revision 1.1.2.4  2002/12/18 15:58:52  dgrisby
 * Proper clean-up of recursive TypeCodes.
 *
 * Revision 1.1.2.3  2001/10/29 17:42:38  dpg1
 * Support forward-declared structs/unions, ORB::create_recursive_tc().
 *
 * Revision 1.1.2.2  2001/06/08 17:12:10  dpg1
 * Merge all the bug fixes from omni3_develop.
 *
 * Revision 1.1.2.1  2001/04/18 17:18:13  sll
 * Big checkin with the brand new internal APIs.
 * These files were relocated and scoped with the omni namespace.
 *
 * Revision 1.10.2.6  2001/03/13 10:32:06  dpg1
 * Fixed point support.
 *
 * Revision 1.10.2.5  2000/11/17 19:09:39  dpg1
 * Support codeset conversion in any.
 *
 * Revision 1.10.2.4  2000/11/09 12:27:55  dpg1
 * Huge merge from omni3_develop, plus full long long from omni3_1_develop.
 *
 * Revision 1.10.2.3  2000/10/06 16:40:55  sll
 * Changed to use cdrStream.
 *
 * Revision 1.10.2.2  2000/09/27 17:25:45  sll
 * Changed include/omniORB3 to include/omniORB4.
 *
 * Revision 1.10.2.1  2000/07/17 10:35:43  sll
 * Merged from omni3_develop the diff between omni3_0_0_pre3 and omni3_0_0.
 *
 * Revision 1.11  2000/07/13 15:26:02  dpg1
 * Merge from omni3_develop for 3.0 release.
 *
 * Revision 1.8.6.5  2000/06/22 10:40:13  dpg1
 * exception.h renamed to exceptiondefs.h to avoid name clash on some
 * platforms.
 *
 * Revision 1.8.6.4  2000/02/15 13:43:43  djr
 * Fixed bug in create_union_tc() -- problem if discriminator was an alias.
 *
 * Revision 1.8.6.3  1999/10/14 17:31:34  djr
 * Minor corrections.
 *
 * Revision 1.8.6.2  1999/10/14 16:22:04  djr
 * Implemented logging when system exceptions are thrown.
 *
 * Revision 1.8.6.1  1999/09/22 14:26:39  djr
 * Major rewrite of orbcore to support POA.
 *
 * Revision 1.7  1999/07/01 10:28:14  djr
 * Added two methods to TypeCode_pairlist.
 * Declare inline methods as inline.
 *
 * Revision 1.6  1999/06/18 21:00:31  sll
 * Updated to CORBA 2.3 mapping.
 *
 * Revision 1.5  1999/05/25 17:47:09  sll
 * Changed to use _CORBA_PseudoValue_Sequence.
 *
 * Revision 1.4  1999/03/11 16:25:59  djr
 * Updated copyright notice
 *
 * Revision 1.3  1999/02/18 15:49:30  djr
 * Simplified NP_namesEqualOrNull()
 *
 * Revision 1.2  1999/01/18 13:56:20  djr
 * Fixed bug in TypeCode_union.
 *
 * Revision 1.1  1999/01/07 17:12:37  djr
 * Initial revision
 *
 */

#ifndef __TYPECODE_H__
#define __TYPECODE_H__

#include <exceptiondefs.h>

OMNI_NAMESPACE_BEGIN(omni)

///////////////////////////
// Forward class defines //
///////////////////////////

// Buffer marshalling & unmarshalling
class TypeCode_offsetTable;
class TypeCode_offsetEntry;

// Helper class used by the NP_equal function
class TypeCode_pairlist;

// TypeCode internal marshalling class
// This class takes care of marshalling & unmarshalling recursive typecodes
class TypeCode_marshaller;

// TypeCode reference counting class
class TypeCode_collector;

// TypeCode implementation classes
class TypeCode_base;

class TypeCode_string;
class TypeCode_wstring;
class TypeCode_objref;
class TypeCode_alias;
class TypeCode_sequence;
class TypeCode_array;
class TypeCode_struct;
class TypeCode_except;
class TypeCode_enum;
class TypeCode_union;

class TypeCode_value;
class TypeCode_value_box;
class TypeCode_abstract_interface;
class TypeCode_local_interface;


// TypeCode parameter list types:
enum TypeCode_paramListType {
  plt_None,
  plt_Simple,
  plt_Complex
};

////////////
// Macros //
////////////
// to cast a CORBA::TypeCode_ptr into a TypeCode_base*

#define ToTcBase(a) ((TypeCode_base*)(CORBA::TypeCode_ptr)a)

inline TypeCode_base*
ToTcBase_Checked(CORBA::TypeCode_ptr a)
{
  if( CORBA::is_nil(a) )
    OMNIORB_THROW(BAD_TYPECODE,
		  BAD_TYPECODE_TypeCodeIsNil,
		  CORBA::COMPLETED_NO);

  return (TypeCode_base*) a;
}

inline const TypeCode_base*
ToConstTcBase_Checked(const CORBA::TypeCode* a)
{
  if (CORBA::is_nil((CORBA::TypeCode_ptr)a))
    OMNIORB_THROW(BAD_TYPECODE,
		  BAD_TYPECODE_TypeCodeIsNil,
		  CORBA::COMPLETED_NO);

  return (const TypeCode_base*)a;
}

//////////////////////////////////////////////////////////////////////
///////////////////////// TypeCode_alignTable ////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_alignTable {
public:

  enum InfoType {
    it_simple,             // know size and alignment
    it_nasty               // data is variable length, or dodgy alignment
  };

  struct Alignment {
    InfoType type;

    struct SimpleAlignment {
      omni::alignment_t alignment;
      CORBA::ULong      size;
    };
    struct NastyAlignment {
      TypeCode_base*    tc;
    };
    union {
      SimpleAlignment simple;
      NastyAlignment  nasty;
    };
  };

  inline TypeCode_alignTable() : pd_entries(0), pd_table(0), pd_owns(0) {}
  inline ~TypeCode_alignTable() {
    if( pd_table ) {
      for( unsigned i = 0; i < pd_entries; i++ )
	if( i_own(i) )  delete pd_table[i];
      delete[] pd_table;
      delete[] pd_owns;
    }
  }

  inline void setNumEntries(unsigned n) {
    pd_table = (new Alignment*[n]);
    unsigned owns_len = n & 31 ? (n>>5) + 1 : (n>>5);
    pd_owns = new CORBA::ULong[owns_len];
    for( unsigned i = 0; i < owns_len; i++ )  pd_owns[i] = 0;
    for( unsigned j = 0; j < n; j++ )         pd_table[j] = 0;
  }
  inline void add(const TypeCode_alignTable& at, unsigned ati) {
    pd_table[pd_entries++] = at.pd_table[ati];
  }
  inline void set(const TypeCode_alignTable& at) {
    setNumEntries(at.entries());
    for( unsigned i = 0; i < at.entries(); i++ )  add(at, i);
  }
  inline void addSimple(omni::alignment_t a, size_t s) {
    unsigned i = new_entry();
    pd_table[i]->type = it_simple;
    pd_table[i]->simple.alignment = a;
    pd_table[i]->simple.size = s;
  }
  inline void addNasty(TypeCode_base* tc) {
    unsigned i = new_entry();
    pd_table[i]->type = it_nasty;
    pd_table[i]->nasty.tc = tc;
  }

  inline CORBA::Boolean is_simple() const {
    return pd_entries == 1 && pd_table[0]->type == it_simple;
  }
  inline CORBA::Boolean has_only_simple() const {
    for( unsigned i = 0; i < pd_entries; i++ )
      if( pd_table[i]->type != it_simple )  return 0;
    return 1;
  }

  inline unsigned entries() const { return pd_entries; }
  inline const Alignment& operator [] (unsigned i) const {
    return *(pd_table[i]);
  }

private:
  inline int i_own(unsigned i) const {
    return pd_owns[i >> 5] & (1 << (i & 31));
  }
  inline void set_i_own(unsigned i) { pd_owns[i >> 5] |= (1 << (i & 31)); }
  inline unsigned new_entry() {
    pd_table[pd_entries] = new Alignment;
    set_i_own(pd_entries);
    return pd_entries++;
  }

  unsigned      pd_entries;
  Alignment**   pd_table;
  CORBA::ULong* pd_owns;
};

//////////////////////////////////////////////////////////////////////
//////////////////////////// TypeCode_base ///////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_base : public CORBA::TypeCode {
public:

  TypeCode_base(CORBA::TCKind tck);

  virtual ~TypeCode_base();

  // omniORB marshalling routines specific to simple typecodes
  virtual void NP_marshalSimpleParams(cdrStream& nbuf,
				      TypeCode_offsetTable*) const;

  // omniORB marshalling routines specific to complex typecodes
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  // omniORB recursive typecode & reference count handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset) {
    return 1;
  }

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId)
  {
    return 1;
  }
  // Complete recursive TypeCodes created using ORB::create_recursive_tc().

  // omniORB equality check support functions
  static const TypeCode_base* NP_expand(const TypeCode_base* tc);
  inline static CORBA::Boolean NP_namesEqual(const char* name1,
					     const char* name2) {
    // returns 1 if both strings are nil or both strings are non-nil and
    // with the same content.
    if (name1 && name2) {
      return (!strcmp(name1,name2));
    }
    else {
      return (name1 == name2);
    }
  }

  // omniORB internal versions of the OMG TypeCode interface
  inline CORBA::TCKind NP_kind() const { return pd_tck; }

  CORBA::Boolean NP_equal(const TypeCode_base* TCp,
			  CORBA::Boolean equivalent,
			  const TypeCode_pairlist* pl) const;
  // If equivalent == 1, perform equivalent test as defined in the
  //                     CORBA 2.3 TypeCode::equivalent() operation.
  // else
  //     perform equality test as defined in the CORBA 2.3 TypeCode::equal()
  //     operation.

  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* pl) const;
  // If equivalent == 1, perform equivalent test as defined in the
  //                     CORBA 2.3 TypeCode::equivalent() operation.
  // else
  //     perform equality test as defined in the CORBA 2.3 TypeCode::equal()
  //     operation.

  virtual const char*          NP_id() const;
  virtual const char*          NP_name() const;
  virtual CORBA::ULong         NP_member_count() const;
  virtual const char*          NP_member_name(CORBA::ULong index) const;
  virtual TypeCode_base*       NP_member_type(CORBA::ULong index) const;
  virtual CORBA::Any*          NP_member_label(CORBA::ULong index) const;
  virtual TypeCode_base*       NP_discriminator_type() const;
  virtual CORBA::Long          NP_default_index() const;
  virtual CORBA::ULong         NP_length() const;
  virtual TypeCode_base*       NP_content_type() const;
  virtual CORBA::UShort        NP_fixed_digits() const;
  virtual CORBA::Short         NP_fixed_scale() const;
  virtual CORBA::Long          NP_param_count() const;
  virtual CORBA::Any*          NP_parameter(CORBA::Long) const;
  virtual CORBA::Short         NP_member_visibility(CORBA::ULong index) const;
  virtual CORBA::ValueModifier NP_type_modifier() const;
  virtual TypeCode_base*       NP_concrete_base_type() const;

  virtual CORBA::Boolean       NP_is_nil() const;

  inline const TypeCode_alignTable& alignmentTable() const {
    return pd_alignmentTable;
  }

  virtual CORBA::Boolean NP_containsAnAlias();
  // Returns true if this TypeCode or any of its members
  // is an alias.  Used in the implementation of
  // aliasExpand() below.

  virtual TypeCode_base* NP_aliasExpand(TypeCode_pairlist*);
  // Return a TypeCode equivalent to this, but with aliases expanded
  // to the actual type.  It is assumed that this will only be called
  // if necassary - ie. the instance it is invoked on really does
  // contain an alias.  This is necassary to reduce the number of
  // calls to NP_containsAnAlias that are necassary.
  //  **This is used to implement aliasExpand() below, and should not
  // be called directly**

  TypeCode_base* NP_compactTc();
  // Return a TypeCode equivalent to this, but with the optional
  // name and member_names removed.

  virtual void removeOptionalNames();
  // This internal function removes any optional names and member_names
  // from the typecode

  virtual void NP_releaseChildren();
  // Release child TypeCodes. Used when freeing loops.

  static TypeCode_base* aliasExpand(TypeCode_base* tc);
  // Return a duplicate of <tc> with aliases expanded to
  // the true type.

  inline TypeCode_base* aliasExpandedTc() { return pd_aliasExpandedTc; }
  // Returns the alias expanded TypeCode if it has been generated.

  inline CORBA::Boolean complete() { return pd_complete; }
  // True if the TypeCode is complete; false if it has incomplete
  // recursive members.

protected:
  TypeCode_alignTable pd_alignmentTable;

  // Flag indicating whether this typecode & all it's child typecodes
  // are 'complete' (i.e. they contain no unresolved recursive sequences)
  CORBA::Boolean pd_complete;

  // The garbage collection and marshalling classes require access to the
  // internal details of typecodes
  friend class TypeCode_collector;
  friend class TypeCode_marshaller;

  // Garbage-collection related fields.
  CORBA::Boolean pd_mark;
  CORBA::ULong   pd_ref_count;

  CORBA::Boolean pd_loop_member;
  CORBA::ULong   pd_internal_ref_count;
  CORBA::ULong   pd_internal_depth;

  // A pointer to the alias expanded version of this typecode
  // if one has been generated, 0 otherwise. If the alias expanded
  // version == this, then the reference is not duplicated.
  TypeCode_base* pd_aliasExpandedTc;

  // A pointer to the compact version of this typecode if one has
  // been generated, 0 otherwise. If the compact version == this,
  // then the reference is not duplicated.
  // This compact version  has all the optional name and member_name 
  // field stripped.
  TypeCode_base* pd_compactTc;

  // The Kind of this TypeCode object
  CORBA::TCKind pd_tck;

  // Linked list within the TypeCode tracker for static TypeCodes
  // allocated in stubs.
  TypeCode_base* pd_next;
  friend class CORBA::TypeCode::_Tracker;

private:
  TypeCode_base();
};

//////////////////////////////////////////////////////////////////////////
// Complex TypeCode sub-classes, used to generate typecodes for complex //
// types. The following typecode sub-classes all use TypeCode_base as   //
// their base, so that all they have to do is override the functions    //
// relevant to their type.                                              //
//////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_string //////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_string : public TypeCode_base {
public:

  // omniORB interface:
  TypeCode_string(CORBA::ULong maxLen);

  virtual ~TypeCode_string();

  virtual void NP_marshalSimpleParams(cdrStream&,
				      TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalSimpleParams(cdrStream& s,
						 TypeCode_offsetTable*);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual CORBA::ULong NP_length() const;
  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

private:
  TypeCode_string();

  CORBA::ULong pd_length;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_fixed ///////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_fixed : public TypeCode_base {
public:

  // omniORB interface:
  TypeCode_fixed(CORBA::UShort digits, CORBA::Short scale);

  virtual ~TypeCode_fixed();

  virtual void NP_marshalSimpleParams(cdrStream&,
				      TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalSimpleParams(cdrStream& s,
						 TypeCode_offsetTable*);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual CORBA::UShort NP_fixed_digits() const;
  virtual CORBA::Short  NP_fixed_scale()  const;

private:
  TypeCode_fixed();

  CORBA::UShort pd_digits;
  CORBA::Short  pd_scale;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_wstring /////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_wstring : public TypeCode_base {
public:

  // omniORB interface:
  TypeCode_wstring(CORBA::ULong maxLen);

  virtual ~TypeCode_wstring();

  virtual void NP_marshalSimpleParams(cdrStream&,
				      TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalSimpleParams(cdrStream& s,
						 TypeCode_offsetTable*);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual CORBA::ULong NP_length() const;
  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

private:
  TypeCode_wstring();

  CORBA::ULong pd_length;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_objref //////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_objref : public TypeCode_base {
public:

  TypeCode_objref(const char* repositoryId, const char* name,
		  CORBA::TCKind tck=CORBA::tk_objref);

  virtual ~TypeCode_objref();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream &s,
						  TypeCode_offsetTable* otbl);

  virtual TypeCode_paramListType NP_paramListType() const;

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char* NP_id() const;
  virtual const char* NP_name() const;

  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

  virtual void removeOptionalNames();

protected:
  TypeCode_objref(CORBA::TCKind tck=CORBA::tk_objref);

  CORBA::String_member pd_repoId;
  CORBA::String_member pd_name;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_alias ///////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_alias : public TypeCode_base {
public:

  TypeCode_alias(const char* repositoryId,
		 const char* name,
		 TypeCode_base* contentTC);

  virtual ~TypeCode_alias();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream& s,
						  TypeCode_offsetTable*);

  // omniORB recursive typecode handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char* NP_id() const;
  virtual const char* NP_name() const;

  virtual TypeCode_base* NP_content_type() const;

  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

  virtual CORBA::Boolean NP_containsAnAlias();
  virtual TypeCode_base* NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

private:
  inline TypeCode_alias() : TypeCode_base(CORBA::tk_alias) {}

  CORBA::String_member pd_repoId;
  CORBA::String_member pd_name;
  CORBA::TypeCode_member pd_content;
};

//////////////////////////////////////////////////////////////////////
////////////////////////// TypeCode_sequence /////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_sequence : public TypeCode_base {
public:

  TypeCode_sequence(CORBA::ULong maxLen, TypeCode_base* contentTC);
  // Normal constructor

  TypeCode_sequence(CORBA::ULong maxLen, CORBA::ULong offset);
  // For recursive sequence members

  virtual ~TypeCode_sequence();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream& s,
						  TypeCode_offsetTable*);

  // omniORB recursive typecode handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);

  // omniORB parameter list handling
  virtual TypeCode_paramListType NP_paramListType() const;

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual CORBA::ULong   NP_length() const;
  virtual TypeCode_base* NP_content_type() const;
  virtual CORBA::Long    NP_param_count() const;
  virtual CORBA::Any*    NP_parameter(CORBA::Long) const;

  virtual CORBA::Boolean NP_containsAnAlias();
  virtual TypeCode_base* NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

  inline CORBA::Boolean  PR_content_is_assigned() const {
    return !CORBA::is_nil(pd_content);
  }

private:
  TypeCode_sequence();

  CORBA::ULong pd_length;
  CORBA::TypeCode_member pd_content;

  CORBA::ULong pd_offset;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_array ///////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_array : public TypeCode_base {
public:

  TypeCode_array(CORBA::ULong maxLen, TypeCode_base* contentTC);

  virtual ~TypeCode_array();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream& s,
						  TypeCode_offsetTable*);

  // omniORB recursive typecode handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual CORBA::ULong NP_length() const;
  virtual TypeCode_base* NP_content_type() const;
  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

  virtual CORBA::Boolean NP_containsAnAlias();
  virtual TypeCode_base* NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

private:
  inline TypeCode_array() : TypeCode_base(CORBA::tk_array) {}

  void generateAlignmentTable();

  CORBA::ULong pd_length;
  CORBA::TypeCode_member pd_content;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_struct //////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_struct : public TypeCode_base {
public:

  struct Member {
    char*               name;
    CORBA::TypeCode_ptr type;
  };


  TypeCode_struct(char* repositoryId, char* name,
		  Member* members, CORBA::ULong memberCount);
  // Consumes <repositoryId>, <name> and <members> (and all
  // the strings and TypeCodes in <members>).  Assumes all
  // arguments are present and correct.

  virtual ~TypeCode_struct();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream&,
						  TypeCode_offsetTable*);

  // omniORB recursive typecode handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);
  
  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char* NP_id() const;
  virtual const char* NP_name() const;
  virtual CORBA::ULong NP_member_count() const;
  virtual const char*  NP_member_name(CORBA::ULong index) const;
  virtual TypeCode_base* NP_member_type(CORBA::ULong index) const;
  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

  virtual CORBA::Boolean NP_containsAnAlias();
  virtual TypeCode_base* NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

private:
  inline TypeCode_struct()
    : TypeCode_base(CORBA::tk_struct),
      pd_members(0), pd_nmembers(0) {}
  // Private constructor - used when unmarshalling a TypeCode.

  void generateAlignmentTable();


  CORBA::String_member pd_repoId;
  CORBA::String_member pd_name;
  Member*              pd_members;
  CORBA::ULong         pd_nmembers;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_except //////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_except : public TypeCode_base {
public:

  TypeCode_except(char* repositoryId, char* name,
		  TypeCode_struct::Member* members,
		  CORBA::ULong memberCount);
  // Consumes <repositoryId>, <name> and <members> (and all
  // the strings and TypeCodes in <members>). Assumes all
  // arguments are present and correct.

  virtual ~TypeCode_except();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream&,
						  TypeCode_offsetTable*);

  // omniORB recursive typecode handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char* NP_id() const;
  virtual const char* NP_name() const;
  virtual CORBA::ULong NP_member_count() const;
  virtual const char* NP_member_name(CORBA::ULong index) const;
  virtual TypeCode_base* NP_member_type(CORBA::ULong index) const;
  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

  virtual CORBA::Boolean NP_containsAnAlias();
  virtual TypeCode_base* NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

private:
  inline TypeCode_except()
    : TypeCode_base(CORBA::tk_except),
      pd_members(0), pd_nmembers(0) {}

  void generateAlignmentTable();


  CORBA::String_member     pd_repoId;
  CORBA::String_member     pd_name;
  TypeCode_struct::Member* pd_members;
  CORBA::ULong             pd_nmembers;
};

//////////////////////////////////////////////////////////////////////
//////////////////////////// TypeCode_enum ///////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_enum : public TypeCode_base {
public:

  TypeCode_enum(const char* repositoryId,
		const char* name,
		const CORBA::EnumMemberSeq& members);

  virtual ~TypeCode_enum();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream& s,
						  TypeCode_offsetTable*);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char* NP_id() const;
  virtual const char* NP_name() const;
  virtual CORBA::ULong NP_member_count() const;
  virtual const char*  NP_member_name(CORBA::ULong index) const;
  virtual CORBA::Long NP_param_count() const;
  virtual CORBA::Any* NP_parameter(CORBA::Long) const;

  CORBA::Long NP_member_index(const char* name) const;
  // Return the index of the member with the given name,
  // or -1 if no such member exists.

  virtual void removeOptionalNames();

private:
  TypeCode_enum();

  CORBA::String_member pd_repoId;
  CORBA::String_member pd_name;

  CORBA::EnumMemberSeq pd_members;
  //?? Consider also storing a lookup array sorted on the name to
  // enable faster lookups.
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_union ///////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_union : public TypeCode_base {
public:
  // This type is used to store discriminator values for all types
  // of discriminator - so must be able to store values as large
  // as the largest discriminator type.
  typedef CORBA::PR_unionDiscriminator       Discriminator;
  typedef CORBA::PR_unionDiscriminatorSigned DiscriminatorSigned;

  TypeCode_union(const char* repoId, const char* name,
		 TypeCode_base* discTC, const CORBA::UnionMemberSeq& members);

  TypeCode_union(const char* repoId, const char* name,
		 TypeCode_base* discTC, const CORBA::PR_unionMember* members,
		 CORBA::ULong memberCount, CORBA::Long deflt);

  virtual ~TypeCode_union();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream& s,
						  TypeCode_offsetTable*);

  // omniORB recursive typecode handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char*    NP_id() const;
  virtual const char*    NP_name() const;
  virtual CORBA::ULong   NP_member_count() const;
  virtual const char*    NP_member_name(CORBA::ULong index) const;
  virtual TypeCode_base* NP_member_type(CORBA::ULong index) const;
  virtual CORBA::Any*    NP_member_label(CORBA::ULong index) const;
  virtual TypeCode_base* NP_discriminator_type() const;
  virtual CORBA::Long    NP_default_index() const;
  virtual CORBA::Long    NP_param_count() const;
  virtual CORBA::Any*    NP_parameter(CORBA::Long) const;

  inline Discriminator NP_member_label_val(CORBA::ULong index) const {
    return pd_members[index].alabel;
  }
  CORBA::Long NP_index_from_discriminator(Discriminator) const;
  // Returns the index of the member corresponding to the given
  // discriminator value. Returns -1 if the value is invalid.
  // (This can only happen if there is no default).

  Discriminator NP_default_value();
  // Returns a value which may be used as either explicit or
  // implicit default for this union.
  //  Must not be called if the union has no default.

  virtual CORBA::Boolean NP_containsAnAlias();
  virtual TypeCode_base* NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

private:
  TypeCode_union();

  struct TcUnionMember {
    CORBA::String_member   aname;
    Discriminator          alabel;  // undefined if default member
    CORBA::TypeCode_member atype;
  };
  typedef _CORBA_PseudoValue_Sequence<TcUnionMember> TcUnionMemberSeq;

  CORBA::String_member   pd_repoId;
  CORBA::String_member   pd_name;
  CORBA::TypeCode_member pd_discrim_tc;

# define TYPECODE_UNION_IMPLICIT_DEFAULT  -1
# define TYPECODE_UNION_NO_DEFAULT        -2
  CORBA::Long pd_default;
  // Index of the default member in in <pd_members>.
  // TYPECODE_UNION_IMPLICIT_DEFAULT if there is no explicit
  // default but there is an implicit default value.
  // TYPECODE_UNION_NO_DEFAULT if all cases are given explicitly.

  TcUnionMemberSeq pd_members;

  // This is a value which may be used as an explicit or implicit
  // default value for the union.
  CORBA::Boolean pd_have_calculated_default_value;
  Discriminator  pd_default_value;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_value ///////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_value : public TypeCode_base {
public:

  struct Member {
    char*               name;
    CORBA::TypeCode_ptr type;
    CORBA::Short        access;
  };

  TypeCode_value(const char* repositoryId, const char* name,
		 CORBA::ValueModifier type_modifier,
		 TypeCode_base* concrete_base,
		 Member* members,
		 CORBA::ULong memberCount);

  virtual ~TypeCode_value();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream &s,
						  TypeCode_offsetTable* otbl);

  virtual TypeCode_paramListType NP_paramListType() const;

  // omniORB recursive typecode & reference count handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);

  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char*          NP_id() const;
  virtual const char*          NP_name() const;

  virtual CORBA::ULong         NP_member_count() const;
  virtual const char*          NP_member_name(CORBA::ULong index) const;
  virtual TypeCode_base*       NP_member_type(CORBA::ULong index) const;
  virtual CORBA::Short         NP_member_visibility(CORBA::ULong index) const;
  virtual CORBA::ValueModifier NP_type_modifier() const;
  virtual TypeCode_base*       NP_concrete_base_type() const;

  virtual CORBA::Boolean       NP_containsAnAlias();
  virtual TypeCode_base*       NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

private:
  TypeCode_value();
  // Private constructor - used when unmarshalling a TypeCode.

  CORBA::String_member 	 pd_repoId;
  CORBA::String_member 	 pd_name;
  Member*                pd_members;
  CORBA::ULong           pd_nmembers;
  CORBA::ValueModifier   pd_modifier;
  CORBA::TypeCode_member pd_base;
};

//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_value_box ///////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_value_box : public TypeCode_base {
public:

  TypeCode_value_box(const char* repositoryId, const char* name,
		     TypeCode_base* boxedTC);

  virtual ~TypeCode_value_box();

  // omniORB marshalling routines specific to complex types
  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream &s,
						  TypeCode_offsetTable* otbl);

  virtual TypeCode_paramListType NP_paramListType() const;

  // OMG Interface:
  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* tcpl) const;

  virtual const char*          NP_id() const;
  virtual const char*          NP_name() const;

  virtual TypeCode_base*       NP_content_type() const;

  virtual CORBA::Boolean       NP_containsAnAlias();
  virtual TypeCode_base*       NP_aliasExpand(TypeCode_pairlist*);

  virtual void removeOptionalNames();

  virtual void NP_releaseChildren();

private:
  TypeCode_value_box();

  CORBA::String_member 	 pd_repoId;
  CORBA::String_member 	 pd_name;
  CORBA::TypeCode_member pd_boxed;
};



//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_abstract_interface //////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_abstract_interface : public TypeCode_objref {
public:

  TypeCode_abstract_interface(const char* repositoryId, const char* name);

  virtual ~TypeCode_abstract_interface();

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream &s,
						  TypeCode_offsetTable* otbl);

private:
  TypeCode_abstract_interface();
};


//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_local_interface /////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_local_interface : public TypeCode_objref {
public:

  TypeCode_local_interface(const char* repositoryId, const char* name);

  virtual ~TypeCode_local_interface();

  static TypeCode_base* NP_unmarshalComplexParams(cdrStream &s,
						  TypeCode_offsetTable* otbl);

private:
  TypeCode_local_interface();
};


//////////////////////////////////////////////////////////////////////
/////////////////////////// TypeCode_indirect ////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_indirect : public TypeCode_base {
public:

  TypeCode_indirect(const char* repoId);

  virtual ~TypeCode_indirect();

  virtual void NP_marshalSimpleParams(cdrStream& nbuf,
				      TypeCode_offsetTable*) const;

  virtual void NP_marshalComplexParams(cdrStream&,
				       TypeCode_offsetTable*) const;

  // omniORB recursive typecode & reference count handling
  virtual CORBA::Boolean NP_complete_recursive_sequences(TypeCode_base* tc,
							 CORBA::ULong offset);

  virtual CORBA::Boolean NP_complete_recursive(TypeCode_base* tc,
					       const char* repoId);

  virtual CORBA::Boolean NP_extendedEqual(const TypeCode_base* TCp,
					  CORBA::Boolean equivalent,
					  const TypeCode_pairlist* pl) const;

  virtual const char*          NP_id() const;
  virtual const char*          NP_name() const;
  virtual CORBA::ULong         NP_member_count() const;
  virtual const char*          NP_member_name(CORBA::ULong index) const;
  virtual TypeCode_base*       NP_member_type(CORBA::ULong index) const;
  virtual CORBA::Any*          NP_member_label(CORBA::ULong index) const;
  virtual TypeCode_base*       NP_discriminator_type() const;
  virtual CORBA::Long          NP_default_index() const;
  virtual CORBA::ULong         NP_length() const;
  virtual TypeCode_base*       NP_content_type() const;
  virtual CORBA::UShort        NP_fixed_digits() const;
  virtual CORBA::Short         NP_fixed_scale() const;
  virtual CORBA::Long          NP_param_count() const;
  virtual CORBA::Any*          NP_parameter(CORBA::Long) const;
  virtual CORBA::Short         NP_member_visibility(CORBA::ULong index) const;
  virtual CORBA::ValueModifier NP_type_modifier() const;
  virtual TypeCode_base*       NP_concrete_base_type() const;

  virtual CORBA::Boolean       NP_containsAnAlias();
  virtual TypeCode_base*       NP_aliasExpand(TypeCode_pairlist*);
  virtual void                 removeOptionalNames();
  virtual void                 NP_releaseChildren();

  inline TypeCode_base* NP_resolved() {
    if (!pd_resolved)
      OMNIORB_THROW(BAD_TYPECODE,
		    BAD_TYPECODE_UnresolvedRecursiveTC,
		    CORBA::COMPLETED_NO);
    return pd_resolved;
  }

  static inline const TypeCode_base* strip(const TypeCode_base* tc) {
    while (tc->NP_kind() == CORBA::_np_tk_indirect)
      tc = ((TypeCode_indirect*)tc)->NP_resolved();
    return tc;
  }

  static inline TypeCode_base* strip(TypeCode_base* tc) {
    while (tc->NP_kind() == CORBA::_np_tk_indirect)
      tc = ((TypeCode_indirect*)tc)->NP_resolved();
    return tc;
  }

private:
  CORBA::String_var pd_repoId;
  TypeCode_base*    pd_resolved;
};



//////////////////////////////////////////////////////////////////////
//////////////////////// TypeCode_offsetEntry ////////////////////////
//////////////////////////////////////////////////////////////////////

// Internal buffer-offset to typecode mapping class

class TypeCode_offsetEntry
{
private:
  friend class TypeCode_offsetTable;

  TypeCode_offsetEntry* pd_next;
  CORBA::ULong pd_offset;
  TypeCode_base* pd_typecode;
};

//////////////////////////////////////////////////////////////////////
//////////////////////// TypeCode_offsetTable ////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_offsetTable
{
public:
  TypeCode_offsetTable();
  ~TypeCode_offsetTable();

  // Constructor to create a new offset table based on an existing one
  // When the new table is created, it assumes the currentOffset field
  // of the parent table to be the base location.
  // EXAMPLE:
  //  .1) The user creates an offsetTable
  //  .2) The user does some work, leaving the currentOffset at _n_.
  //  .3) The user now wants to deal with the offsetTable as if the current
  //      offset wasn't _n_ but was, instead _base_.
  //  .4) A new offsetTable, B, is created, with initial offset of _base_.
  //      Now, a call such as B->addEntry(_m_, _tc_) will be mapped to
  //                          A->addEntry(_m_ + (_n_ - _base_), _tc)
  //      i.e.  The offset passed to B->addEntry is relative to offset zero
  //            in table B.  The is automatically mapped to the corresponding
  //            offset in table A.
  TypeCode_offsetTable(TypeCode_offsetTable* parent, CORBA::Long base_offset);

  // Routine to add an offset->typecode mapping
  void addEntry(CORBA::Long offset, TypeCode_base* typecode);

  // Routines to retrieve typecode by offset or vica versa
  TypeCode_base* lookupOffset(CORBA::Long offset);
  CORBA::Boolean lookupTypeCode(const TypeCode_base* tc, CORBA::Long& offset);

  // Routine to retrieve the current buffer offset
  inline CORBA::Long currentOffset()   { return pd_curr_offset; }
  inline void setOffset(CORBA::Long i) { pd_curr_offset = i;    }

private:
  TypeCode_offsetEntry* pd_table;
  CORBA::Long pd_curr_offset;

  // Fields for use when this offsetTable is actually just a wrapper round
  // an existing offsetTable
  TypeCode_offsetTable* pd_parent_table;
  CORBA::Long pd_parent_base_offset;
};

//////////////////////////////////////////////////////////////////////
////////////////////////// TypeCode_pairlist /////////////////////////
//////////////////////////////////////////////////////////////////////

// Instances of this class are chained together on the stack and are used
// by NP_equal to avoid loops in typecode comparisons

class TypeCode_pairlist
{
public:
  inline TypeCode_pairlist(const TypeCode_pairlist* next,
			   const TypeCode_base* tc1,
			   const TypeCode_base* tc2)
    : d_next(next), d_tc1(tc1), d_tc2(tc2) {}

  const TypeCode_pairlist* d_next;
  const TypeCode_base*     d_tc1;
  const TypeCode_base*     d_tc2;

  static int contains(const TypeCode_pairlist*,
		      const TypeCode_base*, const TypeCode_base*);
  // Returns true if the given list contains the given pair.

  static const TypeCode_base* search(const TypeCode_pairlist*,
				     const TypeCode_base*);
  // Search for given typecode in the pair list, and if
  // found as the second of a pair, return the first in
  // the same pair.  Otherwise return 0.
};

//////////////////////////////////////////////////////////////////////
///////////////////////// TypeCode_marshaller ////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_marshaller
{
public:

  // Marshal/unmarshal to cdrStream
  static void marshal(TypeCode_base* obj,
		      cdrStream& s,
		      TypeCode_offsetTable* otbl);
  static TypeCode_base* unmarshal(cdrStream& s,
				   TypeCode_offsetTable* otbl);

  // Find out what kind of parameter list the given TypeCode Kind requires
  static TypeCode_paramListType paramListType(CORBA::ULong kind);
};

//////////////////////////////////////////////////////////////////////
///////////////////////// TypeCode_collector /////////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_collector
{
public:

  // Duplicate a typecode pointer
  static TypeCode_base* duplicateRef(TypeCode_base* tc);

  // Release a typecode pointer
  static void releaseRef(TypeCode_base* tc);

  // Traverse a typecode tree, marking all nodes that are part of a loop
  static void markLoopMembers(TypeCode_base* tc);

private:

  // Internal routines used by releaseRef

  static CORBA::ULong markLoops(TypeCode_base* tc, CORBA::ULong depth);

  static void countInternalRefs(TypeCode_base* tc);
  static CORBA::Boolean checkInternalRefs(TypeCode_base* tc,
					  CORBA::ULong depth);
};

//////////////////////////////////////////////////////////////////////
//////////////////////// TypeCode_union_helper ///////////////////////
//////////////////////////////////////////////////////////////////////

class TypeCode_union_helper
{
public:

  static TypeCode_union::Discriminator
    extractLabel(const CORBA::Any& discval, CORBA::TypeCode_ptr tc);
  // Extract a discriminator value from the given Any, and cast it to
  // the TypeCode_union::Discriminator type. Checks that the value in
  // <discval> is of type <tc>, and throws BAD_PARAM if not.
  // Also checks that <tc> is a legal union disciminator type,
  // and throws BAD_TYPECODE if not.

  static void insertLabel(CORBA::Any& label,
			  TypeCode_union::Discriminator,
			  CORBA::TypeCode_ptr tc);
  // Insert the discriminator value into the given Any, with the
  // required type.

  static void marshalLabel(TypeCode_union::Discriminator,
			   CORBA::TypeCode_ptr tc, cdrStream& s);
  // Marshal a discriminator value (as the given type).

  static TypeCode_union::Discriminator
    unmarshalLabel(CORBA::TypeCode_ptr tc, cdrStream& s);
  // Unmarshal a discriminator value of the given type from the stream.
  // Throws CORBA::MARSHAL on error.

  static CORBA::Boolean has_implicit_default(TypeCode_base* tc);
  // True if the union has an implicit default - ie. no explicit
  // default given, and not all values of the discriminator type
  // have been used.
  //  This need only be called by the TypeCode_union constructor,
  // as it caches the result.
};

OMNI_NAMESPACE_END(omni)

#endif // __TYPECODE_H__