]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/inc/asn-list.h
Security-54.1.9.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-lib / inc / asn-list.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 // file: .../c++-lib/inc/asn-list.h
20 //
21 // **** NOTE - this is not used or tested due to problems with gcc ****
22 //
23 // Mike Sample
24 // 92/07/02
25 // Copyright (C) 1992 Michael Sample and the University of British Columbia
26 //
27 // This library is free software; you can redistribute it and/or
28 // modify it provided that this copyright/license information is retained
29 // in original form.
30 //
31 // If you modify this file, you must clearly indicate your changes.
32 //
33 // This source code is distributed in the hope that it will be
34 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
35 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
36 //
37 // $Header: /cvs/root/Security/SecuritySNACCRuntime/c++-lib/inc/Attic/asn-list.h,v 1.1.1.1 2001/05/18 23:14:06 mb Exp $
38 // $Log: asn-list.h,v $
39 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
40 // Move from private repository to open source repository
41 //
42 // Revision 1.3 2001/05/05 00:59:18 rmurphy
43 // Adding darwin license headers
44 //
45 // Revision 1.2 2000/06/15 18:48:24 dmitch
46 // Snacc-generated source files, now part of CVS tree to allow for cross-platform build of snaccRuntime.
47 //
48 // Revision 1.1.1.1 2000/03/09 01:00:05 rmurphy
49 // Base Fortissimo Tree
50 //
51 // Revision 1.2 1999/03/21 02:07:32 mb
52 // Added Copy to every AsnType.
53 //
54 // Revision 1.1 1999/02/25 05:21:43 mb
55 // Added snacc c++ library
56 //
57 // Revision 1.6 1997/02/16 20:25:38 rj
58 // check-in of a few cosmetic changes
59 //
60 // Revision 1.5 1995/07/24 17:46:54 rj
61 // operator == and != return bool instead of int.
62 //
63 // #if TCL ... #endif wrapped into #if META ... #endif
64 //
65 // changed `_' to `-' in file names.
66 //
67 // Revision 1.4 1995/02/18 14:06:09 rj
68 // #pragma interface/implementation are GNU specific and need to be wrapped.
69 //
70 // Revision 1.3 1994/10/08 04:18:05 rj
71 // code for meta structures added (provides information about the generated code itself).
72 //
73 // code for Tcl interface added (makes use of the above mentioned meta code).
74 //
75 // virtual inline functions (the destructor, the Clone() function, BEnc(), BDec() and Print()) moved from inc/*.h to src/*.C because g++ turns every one of them into a static non-inline function in every file where the .h file gets included.
76 //
77 // made Print() const (and some other, mainly comparison functions).
78 //
79 // several `unsigned long int' turned into `size_t'.
80 //
81 // Revision 1.2 1994/08/28 10:00:51 rj
82 // comment leader fixed.
83 //
84 // Revision 1.1 1994/08/28 09:20:37 rj
85 // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
86
87 #ifndef _asn_list_h_
88 #define _asn_list_h_
89
90 #ifdef __GNUG__
91 #pragma interface
92 #endif
93
94 #ifdef _IBM_ENC_
95 #include "shmmgr.h" // Guido Grassel 5.8.93
96 #endif /* _IBM_ENC_ */
97
98 template <class T>
99 #ifndef _IBM_ENC_
100 class AsnList
101 #else
102 class AsnList: public MemMgr // Guido Grassel 12.8.93
103 #endif /* _IBM_ENC_ */
104 {
105 protected:
106 unsigned long int count;
107 struct AsnListElmt
108 {
109 T elmt;
110 AsnListElmt *next, *prev;
111 } *first, *curr, *last;
112
113 #ifdef _IBM_ENC_
114 AsnListElmt *first, *curr, *last;
115 #endif /* _IBM_ENC_ */
116
117 public:
118 AsnList():
119 count (0),
120 first (NULL),
121 curr (NULL),
122 last (NULL)
123 {}
124
125 friend ostream &operator << (ostream &os, AsnList &l);
126
127 void SetCurrElmt (unsigned long int index);
128 void SetCurrToFirst() { curr = first; }
129 void SetCurrToLast() { curr = last; }
130
131 // reading member fcns
132 int Count() { return count; }
133 T *First() { return count > 0 ? &first->elmt : NULL; }
134 T *Last() { return count > 0 ? &last->elmt : NULL; }
135 T *Curr() { return curr ? &curr->elmt : NULL; }
136 T *Next() { return curr && curr->next ? &curr->next->elmt : NULL; }
137 T *Prev() { return curr && curr->prev ? &curr->prev->elmt : NULL; }
138
139 // routines that move the curr elmt
140 T *GoNext() { if (curr) curr = curr->next; return Curr(); }
141 T *GoPrev() { if (curr) curr = curr->prev; return Curr(); }
142
143 // write & alloc fcns - returns new elmt
144 T &Append(); // add elmt to end of list
145 T &Prepend(); // add elmt to begginning of list
146 // T &InsertBefore(); insert elmt before current elmt
147 // T &InsertAfter(); insert elmt after current elmt
148
149 // write & alloc & copy - returns list after copying elmt
150 AsnList &AppendAndCopy (T &elmt); // add elmt to end of list
151 AsnList &PrependAndCopy (T &elmt); // add elmt to begginning of list
152 // AsnList &InsertBeforeAndCopy (T &elmt); insert elmt before current elmt
153 // AsnList &InsertAfterAndCopy (T &elmt); insert elmt after current elmt
154
155 virtual AsnType *Clone() const;
156 virtual AsnType *Copy() const;
157
158 // encode and decode routines
159 AsnLen BEncContent (BUF_TYPE b);
160 void BDecContent (BUF_TYPE b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded, ENV_TYPE env);
161 AsnLen BEnc (BUF_TYPE b);
162 void BDec (BUF_TYPE b, AsnLen &bytesDecoded, ENV_TYPE env);
163
164 PDU_MEMBER_MACROS
165
166 #if META
167 static const AsnTypeDesc _desc;
168
169 const AsnTypeDesc *_getdesc() const;
170
171 #if TCL
172 int TclGetVal (Tcl_Interp *) const;
173 int TclSetVal (Tcl_Interp *, const char *val);
174 #endif /* TCL */
175 #endif /* META */
176 };
177
178 // This causes gcc2 on C++ to choke
179
180 #if 0
181 template <class T, class U>
182 int ListsEquiv (AsnList<T> &l1, AsnList<U> &l2);
183
184 template <class T, class U>
185 inline bool operator == (AsnList<T> &l1, AsnList<U> &l2)
186 {
187 return ListsEquiv (l1, l2);
188 }
189
190 template <class T, class U>
191 inline bool operator != (AsnList<T> &l1, AsnList<U> &l2)
192 {
193 return !ListsEquiv (l1,l2);
194 }
195 #endif
196
197 #endif /* conditional include */