FreeCAD C++
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ParameterGrp Class Reference

#include <Base/Parameter.h>

Detailed Description

The parameter container class This is the base class of all classes handle parameter. The class contains a map of key-value pairs in a grouping structure, not unlike the windows registry. It allows the user to set and retrieve values of the type float, long and string. Also it handles importing and exporting groups of parameters and enables streaming to a persistent medium via XML.

Its main task is making user parameter persitent, saving last used values in dialog boxes, setting and retrieving all kind of preferences and so on.
See also
ParameterManager

Public Member Functions

const char * GetGroupName (void) const
 returns the name
 
void NotifyAll ()
 
copy and insertation
void copyTo (Base::Reference< ParameterGrp >)
 make a deep copy to the other group
 
void insertTo (Base::Reference< ParameterGrp >)
 overwrite everything similar, leave the others alone
 
void exportTo (const char *FileName)
 export this group to a file
 
void importFrom (const char *FileName)
 import from a file to this group
 
void insert (const char *FileName)
 insert from a file to this group, overwrite only the similar
 
methods for bool handling
bool GetBool (const char *Name, bool bPreset=false) const
 read bool values or give default
 
void SetBool (const char *Name, bool bValue)
 set a bool value
 
std::vector< bool > GetBools (const char *sFilter=NULL) const
 get a vector of all bool values in this group
 
std::vector< std::pair< std::string, bool > > GetBoolMap (const char *sFilter=NULL) const
 get a map with all bool values and the keys of this group
 
void RemoveBool (const char *Name)
 remove a bool value from this group
 
methods for Int handling
long GetInt (const char *Name, long lPreset=0) const
 read bool values or give default
 
void SetInt (const char *Name, long lValue)
 set a int value
 
std::vector< long > GetInts (const char *sFilter=NULL) const
 get a vector of all int values in this group
 
std::vector< std::pair< std::string, long > > GetIntMap (const char *sFilter=NULL) const
 get a map with all int values and the keys of this group
 
void RemoveInt (const char *Name)
 remove a int value from this group
 
methods for Unsigned Int handling
unsigned long GetUnsigned (const char *Name, unsigned long lPreset=0) const
 read uint values or give default
 
void SetUnsigned (const char *Name, unsigned long lValue)
 set a uint value
 
std::vector< unsigned long > GetUnsigneds (const char *sFilter=NULL) const
 get a vector of all uint values in this group
 
std::vector< std::pair< std::string, unsigned long > > GetUnsignedMap (const char *sFilter=NULL) const
 get a map with all uint values and the keys of this group
 
void RemoveUnsigned (const char *Name)
 remove a uint value from this group
 
methods for Float handling
double GetFloat (const char *Name, double dPreset=0.0) const
 set a float value
 
void SetFloat (const char *Name, double dValue)
 read float values or give default
 
std::vector< double > GetFloats (const char *sFilter=NULL) const
 get a vector of all float values in this group
 
std::vector< std::pair< std::string, double > > GetFloatMap (const char *sFilter=NULL) const
 get a map with all float values and the keys of this group
 
void RemoveFloat (const char *Name)
 remove a float value from this group
 
methods for Blob handling (not implemented yet)
void SetBlob (const char *Name, void *pValue, long lLength)
 set a blob value
 
void GetBlob (const char *Name, void *pBuf, long lMaxLength, void *pPreset=NULL) const
 read blob values or give default
 
void RemoveBlob (const char *Name)
 remove a blob value from this group
 
methods for String handling
void SetASCII (const char *Name, const char *sValue)
 set a string value
 
std::string GetASCII (const char *Name, const char *pPreset=NULL) const
 read a string values
 
void RemoveASCII (const char *Name)
 remove a string value from this group
 
std::vector< std::string > GetASCIIs (const char *sFilter=NULL) const
 
std::vector< std::pair< std::string, std::string > > GetASCIIMap (const char *sFilter=NULL) const
 Same as GetASCIIs() but with key,value map.
 
- Public Member Functions inherited from Base::Subject< const char * >
 Subject ()
 
virtual ~Subject ()
 
void Attach (Observer< const char * > *ToObserv)
 
void Detach (Observer< const char * > *ToObserv)
 
void Notify (const char * rcReason)
 
Observer< const char * > * Get (const char *Name)
 
void ClearObserver ()
 

Protected Member Functions

 ParameterGrp (XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *GroupNode=0L, const char *sName=0L)
 constructor is protected (handle concept)
 
 ~ParameterGrp ()
 destructor is protected (handle concept)
 
Base::Reference< ParameterGrp_GetGroup (const char *Name)
 helper function for GetGroup
 
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * FindElement (XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *Start, const char *Type, const char *Name=0L) const
 
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * FindOrCreateElement (XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *Start, const char *Type, const char *Name) const
 

Protected Attributes

XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * _pGroupNode
 DOM Node of the Base node of this group.
 
std::string _cName
 the own name
 
std::map< std::string,Base::Reference< ParameterGrp > > _GroupMap
 map of already exported groups
 
- Protected Attributes inherited from Base::Subject< const char * >
std::set< Observer< const char * > * > _ObserverSet
 Vector of attached observers.
 

methods for group handling

typedef Base::Reference< ParameterGrphandle
 type of the handle
 
Base::Reference< ParameterGrpGetGroup (const char *Name)
 get a handle to a sub group or create one
 
std::vector< Base::Reference< ParameterGrp > > GetGroups (void)
 get a vector of all sub groups in this group
 
bool IsEmpty (void) const
 test if this group is empty
 
bool HasGroup (const char *Name) const
 test if a special sub group is in this group
 
void RemoveGrp (const char *Name)
 remove a sub group from this group
 
void Clear (void)
 clears everything in this group (all types)
 

Member Function Documentation

◆ FindElement()

XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* ParameterGrp::FindElement ( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *  Start,
const char *  Type,
const char *  Name = 0L 
) const
protected

Find an element specified by Type and Name Search in the parent element Start for the first occurrence of an element of Type and with the attribute Name=Name. On success it returns the pointer to that element, otherwise NULL If the names not given it returns the first occurrence of Type.

◆ FindOrCreateElement()

XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* ParameterGrp::FindOrCreateElement ( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *  Start,
const char *  Type,
const char *  Name 
) const
protected

Find an element specified by Type and Name or create it if not found Search in the parent element Start for the first occurrence of an element of Type and with the attribute Name=Name. On success it returns the pointer to that element, otherwise it creates the element and returns the pointer.

◆ GetASCIIs()

std::vector<std::string> ParameterGrp::GetASCIIs ( const char *  sFilter = NULL) const

Return all string elements in this group as a vector of strings Its also possible to set a filter criteria.

Parameters
sFilteronly strings which name includes sFilter are put in the vector
Returns
std::vector of std::strings

◆ NotifyAll()

void ParameterGrp::NotifyAll ( )

Notifies all observers for all entries except of sub-groups.