FEDEM Model Database  R8.0
Source code of the FEDEM model database
Public Member Functions | Private Member Functions | List of all members
FFaReferenceList< Type > Class Template Reference

A container of FFaReference objects (guarded pointers). More...

#include <FFaReferenceList.H>

Inheritance diagram for FFaReferenceList< Type >:
Inheritance graph
[legend]
Collaboration diagram for FFaReferenceList< Type >:
Collaboration graph
[legend]

Public Member Functions

FFaReferenceList< Type > & operator= (const std::vector< Type * > &ptrs)
 Overloaded assignment operator. More...
 
void push_front (Type *ptr, bool insertNullToo=false)
 Inserts ptr in the front of the list. More...
 
void push_back (Type *ptr, bool insertNullToo=false)
 Inserts ptr at the end of the list. More...
 
void insertPtrAfter (Type *ptr, Type *objInList=NULL)
 Insert ptr after objInList in the list. More...
 
void insert (Type *ptr, size_t idx=0)
 Inserts ptr at position idx in the list. More...
 
void getPtrs (std::vector< Type * > &toFill, bool includeNullToo=false) const
 Fills the provided vector with the pointers contained in the list. More...
 
void setPtrs (const std::vector< Type * > &ptrs)
 Replaces the current contents with the provided vector of pointers. More...
 
void setRefs (const IntVec &IDs)
 Replaces the current contents with the provided new references. More...
 
FFaReference< Type > & operator[] (int idx)
 Indexing operator (for update). More...
 
const FFaReference< Type > & operator[] (int idx) const
 Indexing operator (for read only). More...
 
void setPtr (Type *ptr, int idx)
 Assigns ptr at position idx. More...
 
Type * getPtr (int idx) const
 Returns the pointer at position idx. More...
 
Type * getFirstPtr () const
 Returns the first pointer, or NULL if myRefs is empty. More...
 
Type * getLastPtr () const
 Returns the last pointer, or NULL if myRefs is empty. More...
 
- Public Member Functions inherited from FFaReferenceListBase
void setAutoSizing (bool onOrOff)
 Sets the autoSizing flag. More...
 
bool isAutoSizing () const
 Returns the value of the autoSizing flag. More...
 
void setContextName (const char *name)
 Assigns the context name myContext for this reference. More...
 
const char * getContextName () const
 Returns the context name myContext used by this reference. More...
 
bool erase (int index)
 Erases entry index from the list, decrementing its size by one. More...
 
void clear ()
 Clears the reference list. More...
 
bool shuffle (size_t newFirst)
 Reorders the elements in the list. More...
 
void reverse ()
 Inverts the element order in the list. More...
 
void removePtr (const FFaFieldContainer *ptr)
 Removes all instances of ptr from this list. More...
 
void zeroOutPtr (const FFaFieldContainer *ptr)
 Sets all instances of ptr in this list to zero. More...
 
bool hasPtr (const FFaFieldContainer *ptr, int *index=NULL) const
 Returns true if ptr is present in the list. More...
 
void getBasePtrs (std::vector< FFaFieldContainer * > &toFill) const
 Fills provided vector with the non-NULL pointers in the list. More...
 
FFaFieldContainer * getBasePtr (int idx) const
 Returns the pointer to the idx'th member in the list. More...
 
size_t size () const
 Returns the length of myRefs,. More...
 
bool empty () const
 Returns true if myRefs is empty (zero length). More...
 
void write (std::ostream &os) const
 Writes the reference list to specified output stream. More...
 
void read (std::istream &is)
 Reads the reference list from specified input stream. More...
 

Private Member Functions

FFaReference< Type > * makeNewRef (Type *ptr, int ID=0)
 Convenience method to create and set up a new reference properly. More...
 
FFaReferenceBase * createNewReference () const final
 Virtual method for creating a FFaReference of correct type. More...
 

Additional Inherited Members

- Protected Types inherited from FFaReferenceListBase
using FFaReferenceList = std::list< FFaReferenceBase * >
 Convenience type alias. More...
 
- Protected Member Functions inherited from FFaReferenceListBase
 FFaReferenceListBase ()
 The default constructor initializes the members. More...
 
virtual ~FFaReferenceListBase ()
 The destructor clears the list. More...
 
void insertRefLast (FFaReferenceBase *ref)
 Appends a reference to the end of myRefs. More...
 
FFaReferenceList::const_iterator findPtr (const FFaFieldContainer *ptr) const
 Returns a const_iterator matching a FFaFieldContainer pointer. More...
 
FFaReferenceList::iterator findPtr (const FFaFieldContainer *ptr)
 Returns an iterator matching a FFaFieldContainer pointer. More...
 
FFaReferenceBase * getRefBase (int idx) const
 Returns the pointer at index idx. More...
 
void setOwnerOnRef (FFaReferenceBase *pt)
 Sets this list as the owner of the reference pt. More...
 
void copy (const FFaReferenceListBase *other, bool unresolve=false)
 Copy method used by copy constructors, etc. More...
 
- Protected Attributes inherited from FFaReferenceListBase
FFaReferenceList myRefs
 The actual list of references. More...
 

Detailed Description

template<class Type>
class FFaReferenceList< Type >

A container of FFaReference objects (guarded pointers).

This class provides a container of guarded pointers (FFaReference) that can be used in classes derived from FFaFieldContainer to refer to several objects of classes derived from FFaFieldContainer. The class can be used in two modes: Either like a vector/array with elements automatically set to zero when referred objects are deleted, or like a list where the references/pointers are deleted from the list when the objects referred to cease to exist.

One of the main reasons to use this class is to use it together with FFaField and get automated IO of the list of references. To use this feature, the FFaFieldContainer derived class containing the reference needs an FFaField<FFaReferenceListBase*> object that is initialized with the address of the FFaReferenceList to read/write:

class FmNewClass : FFaFieldContainer
{
// ...
FFaReferenceList<FmSomeClass> someClassReferences;
FFaField<FFaReferenceListBase*> someWrittenReferences;
// ...
};
FmNewClass::FmNewClass()
{
// ...
// Add reference list to book keeping in the FFaFieldContainer
this->addRefList(&someClassReferences);
// Add field to book keeping in FFaFieldContainer
FFA_FIELD_INIT(someWrittenReferences,&someClassReferences,"FILE_KEY_WORD");
// ...
}
#define FFA_FIELD_INIT(field, defaultValue, identifier)
Adds a named field to *this with specified default value.
Definition: FFaFieldContainer.H:228
Base class for the FEDEM model database structure.
Definition: FFaFieldContainer.H:39
A container of FFaReference objects (guarded pointers).
Definition: FFaReferenceList.H:194

Member Function Documentation

◆ createNewReference()

template<class Type >
FFaReferenceBase* FFaReferenceList< Type >::createNewReference ( ) const
inlinefinalprivatevirtual

Virtual method for creating a FFaReference of correct type.

Implements FFaReferenceListBase.

◆ getFirstPtr()

template<class Type >
Type* FFaReferenceList< Type >::getFirstPtr ( ) const
inline

Returns the first pointer, or NULL if myRefs is empty.

◆ getLastPtr()

template<class Type >
Type* FFaReferenceList< Type >::getLastPtr ( ) const
inline

Returns the last pointer, or NULL if myRefs is empty.

◆ getPtr()

template<class Type >
Type* FFaReferenceList< Type >::getPtr ( int  idx) const
inline

Returns the pointer at position idx.

Returns NULL if idx is outside the range.

◆ getPtrs()

template<class Type >
void FFaReferenceList< Type >::getPtrs ( std::vector< Type * > &  toFill,
bool  includeNullToo = false 
) const
inline

Fills the provided vector with the pointers contained in the list.

◆ insert()

template<class Type >
void FFaReferenceList< Type >::insert ( Type *  ptr,
size_t  idx = 0 
)
inline

Inserts ptr at position idx in the list.

If idx is larger than the length of the list, ptr is inserted at the end instead.

◆ insertPtrAfter()

template<class Type >
void FFaReferenceList< Type >::insertPtrAfter ( Type *  ptr,
Type *  objInList = NULL 
)
inline

Insert ptr after objInList in the list.

If objInList is NULL or not found in the list, ptr is inserted at the end instead.

◆ makeNewRef()

template<class Type >
FFaReference<Type>* FFaReferenceList< Type >::makeNewRef ( Type *  ptr,
int  ID = 0 
)
inlineprivate

Convenience method to create and set up a new reference properly.

◆ operator=()

template<class Type >
FFaReferenceList<Type>& FFaReferenceList< Type >::operator= ( const std::vector< Type * > &  ptrs)
inline

Overloaded assignment operator.

◆ operator[]() [1/2]

template<class Type >
FFaReference<Type>& FFaReferenceList< Type >::operator[] ( int  idx)
inline

Indexing operator (for update).

The returned reference can be used almost as a pointer, making it possible to do:

FmSomeClass* somePointer = referenceList[i];
referenceList[i] = somePointer;

◆ operator[]() [2/2]

template<class Type >
const FFaReference<Type>& FFaReferenceList< Type >::operator[] ( int  idx) const
inline

Indexing operator (for read only).

◆ push_back()

template<class Type >
void FFaReferenceList< Type >::push_back ( Type *  ptr,
bool  insertNullToo = false 
)
inline

Inserts ptr at the end of the list.

◆ push_front()

template<class Type >
void FFaReferenceList< Type >::push_front ( Type *  ptr,
bool  insertNullToo = false 
)
inline

Inserts ptr in the front of the list.

◆ setPtr()

template<class Type >
void FFaReferenceList< Type >::setPtr ( Type *  ptr,
int  idx 
)
inline

Assigns ptr at position idx.

myRefs is padded with NULL before idx if it is shorter.

◆ setPtrs()

template<class Type >
void FFaReferenceList< Type >::setPtrs ( const std::vector< Type * > &  ptrs)
inline

Replaces the current contents with the provided vector of pointers.

◆ setRefs()

template<class Type >
void FFaReferenceList< Type >::setRefs ( const IntVec &  IDs)
inline

Replaces the current contents with the provided new references.


The documentation for this class was generated from the following file: