cfl_basevector.h
Go to the documentation of this file.
1 /** @file cfl_basevector.h @brief Class TBaseVector */
2 
3 
4 /* FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2009, 2025 Thomas Moor
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 
23 
24 
25 #ifndef FAUDES_BASEVECTOR_H
26 #define FAUDES_BASEVECTOR_H
27 
28 #include "cfl_definitions.h"
29 #include "cfl_tokenwriter.h"
30 #include "cfl_tokenreader.h"
31 #include "cfl_types.h"
32 #include "cfl_attributes.h"
33 #include <vector>
34 #include <algorithm>
35 
36 // fix mingw toochain
37 #ifdef THIS
38 #undef THIS
39 #endif
40 
41 namespace faudes {
42 
43 /** @addtogroup ContainerClasses */
44 /** @{*/
45 
46 /**
47  * Vector bass class.
48  *
49  * This class is designed as a random access container for a small number of
50  * comperatively large objects, eg a vector of generators to model a decentralized DES.
51  * The API is restricted to simple positional access and there are no explicit
52  * iterators nor is there a deferred copy mechanism. As with other faudes containers,
53  * vBaseVector is the universal base class for all faudes vector data types. The latter
54  * explicitely refer to the element data type and are implemented as templates.
55  *
56  * Internally, the vBaseVector template uses STL vector of pointers to the individual entries.
57  * When adding an entry, you may either do so be refernce or by pointer. When setting
58  * by reference, the vector takes a copy and owns the new entry. When setting by a pointer,
59  * the vector only records the reference. The vector tracks ownership of each entry in order
60  * to properly destruct entries.
61  *
62  * vBaseVector serves as a base class for all libFaudes vectors:
63  * - GeneratorVector (vector or generators)
64  * - EventSetVector (vector of event sets)
65  *
66  * Token io assumes that the type parameter is a faudes type, ie. entries of the vector
67  * provide token io themselfs. To derive a vector class with non-faudes-type entries,
68  * you will need to reimplement token io. As a convenience feature, the vector keeps a record
69  * of filenames associated with individual entries. You can inspect and edit this record via
70  * the FilenameAt members. When writing the vector to a file and all entries have an associated filename,
71  * output will be to the individual files.
72  *
73  */
74 
75 class FAUDES_API vBaseVector : public ExtType {
76 
78 
79 public:
80 
81  using ExtType::operator=;
82  using ExtType::operator==;
83  using ExtType::operator!=;
84 
85  /**
86  * Constructor.
87  */
88  vBaseVector(void);
89 
90  /**
91  * Copy-constructor.
92  *
93  * This will copy the actual elements and we will take ownership of
94  * the copies. If the elements are fauddes sets, the performance penalty
95  * will only show oncle we write to an element.
96  *
97  * @param rOtherVector
98  * Source to copy from.
99  */
100  vBaseVector(const vBaseVector& rOtherVector);
101 
102  /**
103  * Constructor from file.
104  *
105  * @param rFilename
106  * Name of File
107  * @param rLabel
108  * Section for the set in the file;
109  */
110  vBaseVector(const std::string& rFilename, const std::string& rLabel = "Vector");
111 
112  /**
113  * Virtual destructor
114  */
115  virtual ~vBaseVector(void);
116 
117  /**
118  * Assign by reference
119  *
120  * This method will take references from the source entry, i.e., it will not take
121  * copies and will not attain ownership. The caller is hence responsible for the
122  * livetime of the elements. To obtain a full copy, use the copy constror or Assign()
123  * instead.
124  */
125  void AssignByReference(vBaseVector& rSourceVector);
126 
127  /**
128  * Prototype for vector entries.
129  * The virtual base vBaseVector will provide a plain Type object.
130  * Derived vector classes are meant to reimplement this function.
131  *
132  * @return
133  * Element protoype
134  */
135  virtual const Type* Elementp(void) const;
136 
137  /**
138  * Prototype for vector entries.
139  * This is a convenience wrapper for Elementp.
140  *
141  * @return
142  * Element protoype
143  */
144  virtual const Type& Element(void) const;
145 
146  /**
147  * Factory method for vector entries.
148  * This is a convenience wrapper using Elementp.
149  *
150  * @return
151  * New element allocated on heap
152  */
153  virtual Type* NewElement(void);
154 
155  /**
156  * Test whether the specified element is acceptebla for this vector.
157  * This is a convenience wrapper for Elementp.
158  *
159  * @param rElement
160  * Element to type check.
161  * @return
162  * True, if provided element is accepted by this vector.
163  */
164  virtual bool ElementTry(const Type& rElement) const;
165 
166  /**
167  * Clear all vector
168  */
169  virtual void Clear(void);
170 
171  /**
172  * Get size of vector.
173  *
174  * @return
175  * Number of entries.
176  */
177  Idx Size(void) const;
178 
179  /**
180  * Set size of vector.
181  * If the new size is smaller than the current size,
182  * the vector is truncated. If it is larger, default members
183  * are inserted at the end.
184  *
185  * @param len
186  * Number of entries in vector
187  */
188  void Size(Idx len);
189 
190  /**
191  * Check for default configuration aka empty
192  *
193  * @return
194  * True if empty
195  */
196  bool IsDefault(void) const;
197 
198  /**
199  * Check if the vBaseVector is Empty
200  * (amounts to the default configuration)
201  *
202  * @return
203  * True if empty
204  */
205  bool Empty(void) const;
206 
207  /**
208  * convenience typedef for positions (must be unsigned)
209  */
210  typedef size_t Position;
211 
212  /**
213  * Access element.
214  *
215  * @param pos
216  * Specify entry to access
217  * @exception Exception
218  * - Position out of range (id 69)
219  */
220  virtual const Type& At(const Position& pos) const;
221 
222  /**
223  * Access element.
224  *
225  * @param pos
226  * Specify entry to access
227  * @exception Exception
228  * - Position out of range (id 69)
229  */
230  virtual Type& At(const Position& pos);
231 
232 
233  /**
234  * Replace specified entry.
235  * This method takes a copy of the entry to replace and the
236  * vector becomes the owner of the copy.
237  *
238  * @param pos
239  * Position to replace
240  * @param rElem
241  * New entry
242  * @exception Exception
243  * - Position out of range (id 69)
244  * - Cannot cast element type (63)
245  */
246  virtual void Replace(const Position& pos, const Type& rElem);
247 
248  /**
249  * Replace specified entry.
250  * This method avoids to copy the entry to replace and only records the reference.
251  * The vector does not take ownership of the new entry. I.e., when the vector is destroyed, or the
252  * entry is deleted from the vector, the entry itself remains allocated.
253  *
254  * @param pos
255  * Position to replace
256  * @param pElem
257  * New entry
258  * @exception Exception
259  * - Position out of range (id 69)
260  * - Cannot cast element type (63)
261  */
262  virtual void Replace(const Position& pos, Type* pElem);
263 
264  /**
265  * Replace specified entry.
266  * This method reads the sepcified entry from file and the
267  * vector becomes the owner of the new entry.
268  *
269  * @param pos
270  * Position to replace
271  * @param rFileName
272  * New entry to be read from file
273  * @exception Exception
274  * - Position out of range (id 69)
275  */
276  virtual void Replace(const Position& pos, const std::string& rFileName);
277 
278 
279  /**
280  * Erase entry by position.
281  * If the vector owns the entry, it will be destructed.
282  *
283  * @param pos
284  * Specify entry to erase
285  * @exception Exception
286  * - Position out of range (id 69)
287  */
288  virtual void Erase(const Position& pos);
289 
290  /**
291  * Insert specified entry.
292  * This method takes a copy of the entry to be inserted and the
293  * vector becomes the owner of the copy.
294  *
295  * @param pos
296  * Position at which to insert
297  * @param rElem
298  * Element to insert
299  * @exception Exception
300  * - Position out of range (id 69)
301  * - Cannot cast element type (63)
302  */
303  virtual void Insert(const Position& pos, const Type& rElem);
304 
305  /**
306  * Insert specified entry.
307  * This method avoids to make a copy and inserts only a reference. The caller
308  * remains the owner and is responsable for destruction.
309  *
310  * @param pos
311  * Position at which to insert
312  * @param rElem
313  * Element to insert
314  * @exception Exception
315  * - Position out of range (id 69)
316  * - Cannot cast element type (63)
317  */
318  virtual void Insert(const Position& pos, Type* pElem);
319 
320  /**
321  * Insert specified entry.
322  * This method reads the sepcified entry from file and the
323  * vector becomes the owner of the new entry.
324  *
325  * @param pos
326  * Position at which to insert
327  * @param rFileName
328  * Element to insert
329  * @exception Exception
330  * - Position out of range (id 69)
331  */
332  virtual void Insert(const Position& pos, const std::string& rFileName);
333 
334  /**
335  * Append specified entry.
336  * This method takes a copy of the entry to replace and the
337  * vector becomes the owner of the copy.
338  *
339  * @param rElem
340  * Element to append
341  * @exception Exception
342  * - Cannot cast element type (63)
343  */
344  virtual void PushBack(const Type& rElem);
345 
346  /**
347  * Append specified entry.
348  * This method avoids to copy the entry to replace and only records the reference.
349  * The vector does not take ownership of the new entry. I.e., when the vector is destroyed, or the
350  * entry is deleted from the vector, the entry itself remains allocated.
351  *
352  *
353  * @param rElem
354  * Element to insert
355  * @exception Exception
356  * - Cannot cast element type (63)
357  */
358  virtual void PushBack(Type* rElem);
359 
360  /**
361  * Append specified entry.
362  * This method reads the sepcified entry from file and the
363  * vector becomes the owner of the new entry.
364  *
365  * @param rFileName
366  * Element to insert
367  */
368  virtual void PushBack(const std::string& rFileName);
369 
370  /**
371  * Append specified entry.
372  * Synonymous for PushBack.
373  * This method takes a copy of the entry to replace and the
374  * vector becomes the owner of the copy.
375  *
376  * @param rElem
377  * Element to append
378  * @exception Exception
379  * - Cannot cast element type (63)
380  */
381  virtual void Append(const Type& rElem);
382 
383  /**
384  * Append specified entry.
385  * Synonymous for PushBack.
386  * This method avoids to copy the entry to replace and only records the reference.
387  * The vector does not take ownership of the new entry. I.e., when the vector is destroyed, or the
388  * entry is deleted from the vector, the entry itself remains allocated.
389  *
390  *
391  * @param rElem
392  * Element to insert
393  * @exception Exception
394  * - Cannot cast element type (63)
395  */
396  virtual void Append(Type* rElem);
397 
398  /**
399  * Append specified entry.
400  * Synonymous for PushBack.
401  * This method reads the sepcified entry from file and the
402  * vector becomes the owner of the new entry.
403  *
404  * @param rFileName
405  * Element to insert
406  */
407  virtual void Append(const std::string& rFileName);
408 
409  /**
410  * Find element.
411  * This method iterates through the vector to find a matching element. This is
412  * generally inefficient, consider to use an ordered set instead.
413  *
414  * @param rElem
415  * Element to serach for
416  * @return
417  * Position on success (or >= Size() for not found)
418  * @exception Exception
419  * - Cannot cast element type (63)
420  */
421  virtual Position Find(const Type& rElem);
422 
423  /**
424  * Cnsolidate by removing doublets.
425  * This method iterates through the vector to find ad eliminate semantical doublets; i.e., it
426  * refers to equality as implementyed by the faudes type method DoEqual. This is
427  * generally inefficient, consider to use an ordered set instead.
428  */
429  virtual void EraseDoublets(void);
430 
431  /**
432  * Specify a filename.
433  * When each entry has a filename specified,
434  * file io of the vector will be to individual files.
435  *
436  * @param pos
437  * Position of entry
438  * @param rFileName
439  * Filename relative to vector file
440  * @exception Exception
441  * - Position out of range (id 69)
442  */
443  void FilenameAt(const Position& pos, const std::string& rFileName);
444 
445  /**
446  * Get filename of entry.
447  *
448  * @param pos
449  * Position of entry
450  * @return
451  * Filename assoiated with entry
452  * @exception Exception
453  * - Position out of range (id 69)
454  */
455  const std::string& FilenameAt(const Position& pos) const;
456 
457  /**
458  * Take ownership of all entries.
459  * This method will take ownership of all entries, including those, that
460  * have been set by pointer reference. When the vector is destructed, all
461  * entries will be destructed, too. However, write access may invalidate
462  * element pointers.
463  *
464  */
465  void TakeOwnership(void);
466 
467  /**
468  * Take local copies of all entries.
469  * This method will construct local copies of all entries not previously
470  * owned.
471  */
472  void TakeCopies(void);
473 
474 protected:
475 
476 
477  /**
478  * Token output, debugging see Type::DWrite for public wrappers.
479  * The method assumes that the type parameter is a faudes type and uses
480  * the provide write method per entry. Reimplement this function in derived
481  * classes for non-faudes type vectors.
482  * @param rTw
483  * Reference to TokenWriter
484  * @param rLabel
485  * Label of section to write, defaults to name of set
486  * @param pContext
487  * Write context to provide contextual information
488  */
489  virtual void DoDWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
490 
491  /**
492  * Token output, see Type::SWrite for public wrappers.
493  * The method assumes that the type parameter is a faudes type and uses
494  * the provide write method per entry. Reimplement this function in derived
495  * classes for non-faudes type vectors.
496  *
497  * @param rTw
498  * Reference to TokenWriter
499  *
500  * @exception Exception
501  * - IO errors (id 2)
502  */
503  virtual void DoSWrite(TokenWriter& rTw) const;
504 
505  /**
506  * Token output, see Type::Write for public wrappers.
507  * The method assumes that the type parameter is a faudes type and uses
508  * the provide write method per entry. Reimplement this function in derived
509  * classes for non-faudes type vectors.
510  *
511  * @param rTw
512  * Reference to TokenWriter
513  * @param rLabel
514  * Label of section to write, defaults to name of set
515  * @param pContext
516  * Write context to provide contextual information
517  */
518  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
519 
520  /**
521  * Token output strict XML, see Type::XWrite for public wrappers.
522  * The method assumes that the type parameter is a faudes type and uses
523  * the provide writed method per entry. Reimplement this function in derived
524  * classes for non-faudes type vectors.
525  *
526  * @param rTw
527  * Reference to TokenWriter
528  * @param rLabel
529  * Label of section to write, defaults to name of set
530  * @param pContext
531  * Write context to provide contextual information
532  */
533  virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
534 
535  /**
536  * Token input, see Type::Read for public wrappers.
537  * The method assumes that the type parameter is a faudes type and uses
538  * the provide read method per entry. Reimplement this function in derived
539  * classes for non-faudes type vectors.
540  * By convention, the default label "" should be translated to some meaningful default,
541  * eg "GeneratorVector" for a vector of generators. The pContext pointer can be type-checked
542  * and interpreted, ie as a symboltable to provide symbolic names. It is also
543  * passed on to vector entries.
544  *
545  * @param rTr
546  * Reference to TokenReader
547  * @param rLabel
548  * Label of section to read, defaults to name of set
549  * @param pContext
550  * Read context to provide contextual information
551  */
552  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
553 
554  /** Assignment method (we will take copies and own all those thereafter) */
555  void DoAssign(const vBaseVector& rSourceVector);
556 
557  /**
558  * Test equality of configuration data.
559  *
560  * To be equal, all elements must match.
561  *
562  * @param rOther
563  * Other object to compare with.
564  * @return
565  * True on match.
566  */
567  bool DoEqual(const vBaseVector& rOther) const;
568 
569 
570  /** Internal entry data type */
572  public:
574  std::string mFileName;
575  bool mMine;
576  };
577 
578  /** STL vector of element */
579  std::vector<ElementRecord> mVector;
580 
581  /** convenience typedef */
582  typedef std::vector<ElementRecord>::iterator iterator;
583 
584 private:
585 
586  /** Current/cached faudes type-name */
587  std::string mFaudesTypeName;
588 
589  /** Current/cached name of elements (use protected accessor methods for caching) */
590  std::string mElementTag;
591 
592 protected:
593 
594  /** Defauft name of elements (if not over written by registry) */
595  std::string mElementTagDef;
596 
597 private:
598 
599  /** Name of TBaseVector */
600  std::string mMyName;
601 
602 };
603 
604 
605 /** @} doxygen group */
606 
607 
608 /** @addtogroup ContainerClasses */
609 /** @{*/
610 
611 /**
612  * Vector template.
613  *
614  * The vector templates specializes the bass vBaseVector in that it uses the template
615  * parameter to specify the type of its entries. See vBaseVector for element access
616  * methods.
617  *
618  * TVectorSet serves is used to implement the libFaudes vectors
619  * - GeneratorVector (vector or generators)
620  * - SytemVector (vector or generators)
621  * - EventSetVector (vector of event sets)
622  * - AlphabetVector (vector of event sets)
623  *
624  *
625  */
626 
627 template<class T>
629 
631 
632 public:
633 
634  using vBaseVector::operator=;
635  using vBaseVector::operator==;
636  using vBaseVector::operator!=;
637  using vBaseVector::Insert;
638  using vBaseVector::Erase;
639 
640  /**
641  * Constructor.
642  */
643  TBaseVector(void);
644 
645  /**
646  * Copy-constructor.
647  *
648  * @param rOtherSet
649  * Source to copy from
650  */
651  TBaseVector(const TBaseVector& rOtherSet);
652 
653  /**
654  * Copy-constructor. This version takes any vector as source,
655  * but throughs an exception, if element types dont match.
656  *
657  * @param rOtherSet
658  * Source to copy from
659  * @exception Exception
660  * - Cannot cast elements (63)
661  */
662  TBaseVector(const vBaseVector& rOtherSet);
663 
664  /**
665  * Constructor from file.
666  *
667  * @param rFilename
668  * Name of File
669  * @param rLabel
670  * Section for the set in the file;
671  */
672  TBaseVector(const std::string& rFilename, const std::string& rLabel = "BaseVector");
673 
674  /**
675  * Virtual destructor
676  */
677  virtual ~TBaseVector(void);
678 
679 
680  /**
681  * Prototype for vector entries.
682  * This template class uses the virtual function to know its element type.
683  *
684  * @return
685  * Element protoype
686  */
687  virtual const T* Elementp(void) const;
688 
689  /**
690  * Test whether the specified element is acceptebla for this vector.
691  * This is a convenience wrapper for Elementp.
692  *
693  * @param rElement
694  * Element to type check.
695  * @return
696  * True, if provided element is accepted by this vector.
697  */
698  virtual bool ElementTry(const Type& rElement) const;
699 
700  /**
701  * convenience typedef for positions
702  */
703  typedef std::vector<int>::size_type Position;
704 
705  /**
706  * Access element.
707  *
708  * @param pos
709  * Specify entry to access
710  * @exception Exception
711  * - Position out of range (id 69)
712  */
713  virtual const T& At(const Position& pos) const;
714 
715  /**
716  * Access element.
717  *
718  * @param pos
719  * Specify entry to access
720  * @exception Exception
721  * - Position out of range (id 69)
722  */
723  virtual T& At(const Position& pos);
724 
725  /**
726  * Iterator class for high-level API similar to TBaseSet.
727  *
728  */
729  class Iterator;
730  class CIterator;
731 
732  /**
733  * Iterator to the begin of set
734  *
735  * @return
736  * Iterator
737  */
738  Iterator Begin(void);
739 
740  /**
741  * Iterator to the begin of set, const variant
742  *
743  * @return
744  * Iterator
745  */
746  CIterator Begin(void) const;
747 
748  /**
749  * Iterator to the end of set
750  *
751  * @return
752  * Iterator
753  */
754  Iterator End(void);
755 
756  /**
757  * Iterator to the end of set, const variant
758  *
759  * @return
760  * Iterator
761  */
762  CIterator End(void) const;
763 
764  /**
765  * Insert specified entry.
766  *
767  * Insert with no position defaults to Append/PushBack
768  *
769  *
770  * @param pos
771  * Position at which to insert
772  * @param rElem
773  * Element to insert
774  * @exception Exception
775  * - Position out of range (id 69)
776  * - Cannot cast element type (63)
777  */
778  virtual void Insert(const T& rElem);
779 
780  /**
781  * Erase specified entry.
782  *
783  * @param vit
784  * Iterator to element to erase
785  */
786  virtual Iterator Erase(const Iterator& vit);
787 
788  /**
789  * Iterator class, e add one layer of dereferencing.
790  */
791  class Iterator : public std::vector<ElementRecord>::iterator {
792  public:
793  /** Default contructor */
794  Iterator(void) : std::vector<ElementRecord>::iterator() {};
795  /** Copy constructor */
796  Iterator(const Iterator& fit) : std::vector<ElementRecord>::iterator(fit) {};
797  /** Copy constructor from STL itertor */
798  Iterator(const typename std::vector<ElementRecord>::iterator& sit) : std::vector<ElementRecord>::iterator(sit) {};
799  /** Get as STL iterator */
800  const typename std::vector<ElementRecord>::iterator& StlIterator(void) const {return *this;};
801  /** Reimplement dereference */
802  T* operator-> (void) const {
803  return dynamic_cast<T*>(std::vector<ElementRecord>::iterator::operator*().pElement);
804  };
805  /** Reimplement derefernce */
806  T& operator* (void) const {
807  return *( dynamic_cast<T*>(std::vector<ElementRecord>::iterator::operator*().pElement) );
808  };
809  };
810 
811  /**
812  * Iterator class, const variant
813  */
814  class CIterator : public std::vector<ElementRecord>::const_iterator {
815  public:
816  /** Default contructor */
817  CIterator(void) : std::vector<ElementRecord>::const_iterator() {};
818  /** Copy constructor */
819  CIterator(const Iterator& fit) : std::vector<ElementRecord>::const_iterator(fit) {};
820  /** Copy constructor from STL itertor */
821  CIterator(const typename std::vector<ElementRecord>::const_iterator& sit) : std::vector<ElementRecord>::const_iterator(sit) {};
822  /** Reimplement dereference */
823  const T* operator-> (void) const {
824  return dynamic_cast<const T*>(std::vector<ElementRecord>::const_iterator::operator*().pElement);
825  };
826  /** Reimplement derefernce */
827  const T& operator* (void) const {
828  return *( dynamic_cast<const T*>(std::vector<ElementRecord>::const_iterator::operator*().pElement) );
829  };
830  };
831 
832 
833  protected:
834 
835  /** Assignment method */
836  void DoAssign(const TBaseVector<T>& rSourceVector);
837 
838 
839 };
840 
841 
842 /** @} doxygen group */
843 
844 
845 
846 /*
847 ******************************************************************************************
848 ******************************************************************************************
849 ******************************************************************************************
850 
851 Implementation of TBaseVector
852 
853 ******************************************************************************************
854 ******************************************************************************************
855 ******************************************************************************************
856 */
857 
858 /* convenience access to relevant scopes */
859 #define THIS TBaseVector<T>
860 #define TEMP template<class T>
861 #define BASE vBaseVector
862 
863 
864 // faudes type std
865 FAUDES_TYPE_TIMPLEMENTATION(Void,THIS,vBaseVector,TEMP)
866 
867 // TBaseVector()
869  vBaseVector()
870 {
871  FD_DC("TBaseVector(" << this << ")::TBaseVector()");
872 }
873 
874 
875 // TBaseVector(filename)
876 TEMP THIS::TBaseVector(const std::string& rFileName, const std::string& rLabel) :
877  vBaseVector()
878 {
879  FD_DC("TBaseVector(" << this << ")::TBaseVector()");
880  // do read;
881  Read(rFileName,rLabel);
882 }
883 
884 
885 // TBaseVector(rOtherSet)
886 TEMP THIS::TBaseVector(const TBaseVector& rOtherVector) :
887  vBaseVector()
888 {
889  FD_DC("TBaseVector(" << this << ")::TBaseVector(rOtherVector " << &rOtherVector << "): copy construct");
890  DoAssign(rOtherVector);
891 }
892 
893 // TBaseVector(rOtherSet)
894 TEMP THIS::TBaseVector(const vBaseVector& rOtherVector) :
895  vBaseVector()
896 {
897  FD_DC("TBaseVector(" << this << ")::TBaseVector([v] rOtherVector " << &rOtherVector << "): copy construct");
898  Assign(rOtherVector);
899 }
900 
901 // destructor
902 TEMP THIS::~TBaseVector(void) {
903  FD_DC("TBaseVector(" << this << ")::~TBaseVector()");
904 }
905 
906 
907 // element prototype
908 TEMP const T* THIS::Elementp(void) const {
909  static T tproto;
910  return &tproto;
911 }
912 
913 // test element type
914 TEMP bool THIS::ElementTry(const Type& rElement) const {
915  FD_DC("TBaseVector::ElementTry(): casting from " << typeid(rElement).name() << " to " << typeid(*Elementp()).name());
916  return Elementp()->Cast(&rElement)!=NULL;
917 }
918 
919 
920 // assignment
921 TEMP void THIS::DoAssign(const THIS& rSourceVector) {
922  FD_DC("TBaseVector(" << this << ")::DoAssign(rOtherVector " << &rSourceVector << ")");
923  // base can do it
924  BASE::DoAssign(rSourceVector);
925  // done
926  FD_DC("TBaseVector(" << this << ")::DoAssign(rOtherVector " << &rSourceVector << "): done");
927 }
928 
929 // At()
930 TEMP const T& THIS::At(const Position& pos) const {
931 #ifdef FAUDES_CHECKED
932  if(pos >= mVector.size()) {
933  std::stringstream errstr;
934  errstr << "index out of range" << std::endl;
935  throw Exception("TBaseVector::At", errstr.str(), 62);
936  }
937 #endif
938 #ifdef FAUDES_DEBUG_CODE
939  if(!dynamic_cast<T*>(mVector[pos].pElement)){
940  std::stringstream errstr;
941  errstr << "internal type error" << std::endl;
942  throw Exception("TBaseVector::At", errstr.str(), 63);
943  }
944 #endif
945  return *dynamic_cast<T*>(mVector[pos].pElement);
946 }
947 
948 // At()
949 TEMP T& THIS::At(const Position& pos) {
950 #ifdef FAUDES_CHECKED
951  if(pos >= mVector.size()) {
952  std::stringstream errstr;
953  errstr << "index out of range" << std::endl;
954  throw Exception("TBaseVector::At", errstr.str(), 62);
955  }
956 #endif
957 #ifdef FAUDES_DEBUG_CODE
958  if(!dynamic_cast<T*>(mVector[pos].pElement)){
959  std::stringstream errstr;
960  errstr << "internal type error" << std::endl;
961  throw Exception("TBaseVector::At", errstr.str(), 63);
962  }
963 #endif
964  return *dynamic_cast<T*>(mVector[pos].pElement);
965 }
966 
967 
968 // iterators
969 TEMP typename THIS::Iterator THIS::Begin(void) { return Iterator(mVector.begin());}
970 TEMP typename THIS::CIterator THIS::Begin(void) const { return CIterator(mVector.begin());}
971 TEMP typename THIS::Iterator THIS::End(void) { return Iterator(mVector.end());}
972 TEMP typename THIS::CIterator THIS::End(void) const { return CIterator(mVector.end());}
973 
974 // set style element access
975 TEMP void THIS::Insert(const T& rElem) { Append(rElem); };
976 TEMP typename THIS::Iterator THIS::Erase(const Iterator& pit) {
977  std::vector<ElementRecord>::iterator sit=pit.StlIterator();
978  if(sit->mMine) delete sit->pElement;
979  mVector.erase(sit++);
980  Iterator rit(sit);
981  return rit;
982 };
983 
984 
985 /* undefine local shortcuts */
986 #undef THIS
987 #undef TEMP
988 #undef BASE
989 
990 
991 } // namespace faudes
992 
993 #endif
#define TEMP
#define THIS
#define FD_DC(message)
#define FAUDES_API
Definition: cfl_platform.h:80
#define FAUDES_TAPI
Definition: cfl_platform.h:83
Class TokenReader.
Class TokenWriter.
#define FAUDES_TYPE_TDECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:891
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:880
#define FAUDES_TYPE_TIMPLEMENTATION(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:985
CIterator(const typename std::vector< ElementRecord >::const_iterator &sit)
CIterator(const Iterator &fit)
Iterator(const typename std::vector< ElementRecord >::iterator &sit)
Iterator(const Iterator &fit)
const std::vector< ElementRecord >::iterator & StlIterator(void) const
std::vector< int >::size_type Position
TBaseVector(const std::string &rFilename, const std::string &rLabel="BaseVector")
virtual const T * Elementp(void) const
virtual bool ElementTry(const Type &rElement) const
CIterator End(void) const
virtual Iterator Erase(const Iterator &vit)
virtual const T & At(const Position &pos) const
virtual void Insert(const T &rElem)
virtual ~TBaseVector(void)
TBaseVector(const vBaseVector &rOtherSet)
Iterator End(void)
Iterator Begin(void)
TBaseVector(const TBaseVector &rOtherSet)
void DoAssign(const TBaseVector< T > &rSourceVector)
CIterator Begin(void) const
virtual T & At(const Position &pos)
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Definition: cfl_types.cpp:267
virtual Type & Assign(const Type &rSrc)
Definition: cfl_types.cpp:82
virtual void Insert(const Position &pos, const Type &rElem)
std::string mElementTagDef
std::string mFaudesTypeName
virtual void Erase(const Position &pos)
std::string mElementTag
std::vector< ElementRecord >::iterator iterator
std::vector< ElementRecord > mVector
uint32_t Idx

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen