ASN1C C/C++ Common Runtime  ASN1C v7.2.x
ASN1CSeqOfList.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2018 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
24 #ifndef _ASN1CSEQOFLIST_H_
25 #define _ASN1CSEQOFLIST_H_
26 
27 #include <stdlib.h>
28 #include "rtsrc/asn1CppTypes.h"
38 //
40 // ASN1CSeqOfList
41 //
42 // Doubly-linked list implementation. This class provides all functionalty
43 // necessary for linked list. To iterate list use methods iterator,
44 // iteratorFrom, iteratorFromLast.
45 //
46 // Note: this implementation is not thread-safe.
47 //
48 // ASN1CSeqOfListIterator
49 //
50 // An iterator for lists that allows the programmer to traverse the
51 // list in either direction and modify the list during iteration.
52 //
53 // Author Artem Bolgar
54 // version 1.09, 12 Nov, 2003
55 // version 1.08, 11 Feb, 2003
56 //
57 #ifndef _NO_UTILS_CLASSES
58 
59 class EXTRTCLASS ASN1CSeqOfList;
60 
62 //
63 // ASN1CSeqOfListIterator
64 //
75 class EXTRTCLASS ASN1CSeqOfListIterator {
76  friend class ASN1CSeqOfList;
77  protected:
78  ASN1CSeqOfList* pSeqList; // pointer to the list
79  OSRTDListNode* nextNode; // next node
80  OSRTDListNode* lastNode; // last returned node
81  volatile int expectedModCount; // expect modification counter
82  int stat;
83 
84  EXTRTMETHOD ASN1CSeqOfListIterator(ASN1CSeqOfList* list);
85  EXTRTMETHOD ASN1CSeqOfListIterator(ASN1CSeqOfList* list, OSRTDListNode* startNode);
86 
87  public:
98  inline OSBOOL hasNext() { return OSBOOL(nextNode != 0); }
99 
110  inline OSBOOL hasPrev() { return OSBOOL(nextNode != 0); }
111 
121  EXTRTMETHOD void* next();
122 
133  EXTRTMETHOD void* prev();
134 
146  EXTRTMETHOD int remove();
147 
161  EXTRTMETHOD int set(void* data);
162 
178  EXTRTMETHOD int insert(void* data);
179 
180  /* Returns the state of iterator. 0 if it is OK, RTERR_* value otherwise */
181  inline int getState () { return stat; }
182 
183  protected:
184  inline void* operator new(size_t, void* data) { return data; }
185 #if !defined(__xlC__)
186  inline void operator delete(void*, void*) {}
187 #endif
188 #ifndef __BORLANDC__
189  inline void operator delete(void*, size_t) {}
190 #endif
191 } ;
192 
193 
195 //
196 // ASN1CSeqOfList
197 //
204 class EXTRTCLASS ASN1CSeqOfList : public ASN1CType {
205  friend class ASN1CSeqOfListIterator;
206  protected:
207  OSRTDList* pList; // list
208  volatile int modCount; // modification counter
209  OSBOOL wasAssigned;
210 
211  // The following protected ctor could be used to perform lists' operation,
212  // which do not require the memory allocation.
213  EXTRTMETHOD ASN1CSeqOfList (OSRTDList& lst);
214  EXTRTMETHOD ASN1CSeqOfList (ASN1TSeqOfList& lst);
215  EXTRTMETHOD ASN1CSeqOfList (ASN1TPDUSeqOfList& lst);
216 
217  public:
218 
232  EXTRTMETHOD ASN1CSeqOfList (OSRTMessageBufferIF& msgBuf, OSRTDList& lst,
233  OSBOOL initBeforeUse = TRUE);
234 
241  EXTRTMETHOD ASN1CSeqOfList (OSRTMessageBufferIF& msgBuf);
242 
249  EXTRTMETHOD ASN1CSeqOfList (ASN1CType& ccobj);
250 
264  EXTRTMETHOD ASN1CSeqOfList (OSRTMessageBufferIF& msgBuf, ASN1TSeqOfList& lst);
265 
279  EXTRTMETHOD ASN1CSeqOfList (ASN1CType& ccobj, ASN1TSeqOfList& lst);
280 
294  EXTRTMETHOD ASN1CSeqOfList (OSRTMessageBufferIF& msgBuf, ASN1TPDUSeqOfList& lst);
295 
296  EXTRTMETHOD ASN1CSeqOfList (OSRTContext& ctxt, OSRTDList& lst,
297  OSBOOL initBeforeUse = TRUE);
298  EXTRTMETHOD ASN1CSeqOfList (OSRTContext& ctxt);
299  EXTRTMETHOD ASN1CSeqOfList (OSRTContext& ctxt, ASN1TSeqOfList& lst);
300  EXTRTMETHOD ASN1CSeqOfList (OSRTContext& ctxt, ASN1TPDUSeqOfList& lst);
301 
302  EXTRTMETHOD ~ASN1CSeqOfList();
303 
304  // Appends new list node with data
316  EXTRTMETHOD void append(void* data);
317 
318  // Appends array to list data. Data won't be copied, just assigned.
333  EXTRTMETHOD void appendArray
334  (const void* data, OSSIZE numElems, OSSIZE elemSize);
335 
336  // Appends array to list data. Data will be copied.
351  EXTRTMETHOD void appendArrayCopy
352  (const void* data, OSSIZE numElems, OSSIZE elemSize);
353 
357  inline void init () {
358  rtxDListInit (pList);
359  }
360 
361  // Inserts new list node at the specified index
374  EXTRTMETHOD void insert(int index, void* data);
375 
376  // Removes list node at specified index from the list
388  EXTRTMETHOD void remove(int index);
389 
390  // Removes the first occurrence of the specified element in the list.
401  EXTRTMETHOD void remove(void* data);
402 
403  // Removes the first element from the list.
410  inline void removeFirst() {
411  remove(pList->head);
412  }
413 
414  // Removes the last element from the list.
421  inline void removeLast() {
422  remove(pList->tail);
423  }
424 
425  // Returns index of the list node with specified data
435  EXTRTMETHOD int indexOf(void* data) const;
436 
437  // Returns 'TRUE' if this list contains the specified element.
446  inline OSBOOL contains (void* data) const {
447  return indexOf(data) != -1;
448  }
449 
456  EXTRTMETHOD void* getFirst();
457 
464  EXTRTMETHOD void* getLast();
465 
472  EXTRTMETHOD void* get (int index) const;
473 
482  EXTRTMETHOD void* set (int index, void* data);
483 
487  EXTRTMETHOD void clear();
488 
493  EXTRTMETHOD void freeMemory();
494 
500  EXTRTMETHOD OSBOOL isEmpty() const;
501 
507  EXTRTMETHOD OSSIZE size() const;
508 
515  EXTRTMETHOD ASN1CSeqOfListIterator* iterator();
516 
517  // Creates iterator from the tail of the list
525  EXTRTMETHOD ASN1CSeqOfListIterator* iteratorFromLast();
526 
527  // Creates iterator from the node with specified data
536  EXTRTMETHOD ASN1CSeqOfListIterator* iteratorFrom(void* data);
537 
547  EXTRTMETHOD void* toArray (OSSIZE elemSize);
548 
549  // Converts to array
566  EXTRTMETHOD void* toArray
567  (void* pArray, OSSIZE elemSize, OSSIZE allocatedElems);
568 
569  // Returns element at specified index
577  inline void* operator[](int index) const {
578  return get(index);
579  }
580 
581  inline operator OSRTDList* () {
582  return pList;
583  }
584  protected:
585  // Removes specified node from the list
586  EXTRTMETHOD void remove(OSRTDListNode* node);
587 
588  // Inserts new node ('data') before another node ('node')
589  EXTRTMETHOD void insertBefore(void* data, OSRTDListNode* node);
590 
591  // Inserts new node ('data') after another node ('node')
592  EXTRTMETHOD void insertAfter(void* data, OSRTDListNode* node);
593 
594 
595 } ;
596 #else
597 typedef class _ASN1CSeqOfList : public ASN1CType {
598  public:
599  _ASN1CSeqOfList (OSRTMessageBufferIF& msgBuf, OSRTDList& lst,
600  OSBOOL initBeforeUse = TRUE) : ASN1CType (msgBuf) {}
601  _ASN1CSeqOfList (OSRTMessageBufferIF& msgBuf, ASN1TSeqOfList& lst) :
602  ASN1CType (msgBuf) {}
603  _ASN1CSeqOfList (OSRTMessageBufferIF& msgBuf) : ASN1CType (msgBuf) {}
605 
606 #endif // _NO_UTILS_CLASSES
607 
612 #endif // _ASN1CSEQOFLIST_H_
OSRTDListNode * tail
Definition: rtxDList.h:67
OSRTDListNode * head
Definition: rtxDList.h:66
Definition: ASN1CSeqOfList.h:204
void init()
Definition: ASN1CSeqOfList.h:357
OSBOOL hasNext()
Definition: ASN1CSeqOfList.h:98
EXTRTMETHOD void insert(int index, void *data)
void rtxDListInit(OSRTDList *pList)
Definition: rtxDList.h:64
Definition: asn1CppTypes.h:867
OSBOOL contains(void *data) const
Definition: ASN1CSeqOfList.h:446
Definition: asn1CppTypes.h:314
void removeLast()
Definition: ASN1CSeqOfList.h:421
Definition: rtxDList.h:52
void append(OSRTDList &llist, void *pdata)
Definition: asn1CppTypes.h:394
Definition: asn1CppTypes.h:853
EXTRTMETHOD int insert(void *data)
Definition: OSRTContext.h:65
OSBOOL hasPrev()
Definition: ASN1CSeqOfList.h:110
void * operator[](int index) const
Definition: ASN1CSeqOfList.h:577
Definition: ASN1CSeqOfList.h:75
void removeFirst()
Definition: ASN1CSeqOfList.h:410