29#ifndef _GENICAM_PERSISTENCE_H
30#define _GENICAM_PERSISTENCE_H
35#include <GenApi/SelectorSet.h>
41namespace GENAPI_NAMESPACE
45 GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IPersistScript
72 bool LoadFromBag(INodeMap *pNodeMap,
bool Verify =
true, GENICAM_NAMESPACE::gcstring_vector *pErrorList = NULL);
80 int64_t
StoreToBag(INodeMap *pNodeMap,
const int MaxNumPersistSkriptEntries = -1, GENICAM_NAMESPACE::gcstring_vector *pFeatureFilter = NULL);
87 virtual void Destroy();
105 CSelectorState* AllocateSelector();
106 void DeleteSelector(CSelectorState*& p);
109 void Push(
const char *name,
const char *value, CSelectorState *ps);
117 CSelectorState* pState;
120 class GENAPI_DECL const_iterator
125 const_iterator(Triplet *pTriplet = NULL);
126 const_iterator(
const const_iterator&);
127 const_iterator&
operator=(
const const_iterator&);
131 const Triplet & operator * (
void)
const;
132 const Triplet * operator -> (
void)
const;
133 const_iterator & operator ++ (
void);
134 const_iterator operator ++ (
int);
135 const_iterator & operator += (intptr_t iInc);
136 const_iterator operator + (intptr_t iInc)
const;
137 intptr_t operator - (
const const_iterator &iter)
const;
138 bool operator == (
const const_iterator &iter)
const;
139 bool operator != (
const const_iterator &iter)
const;
147 const_iterator GetBegin();
148 const_iterator GetBegin()
const;
149 const_iterator GetEnd();
150 const_iterator GetEnd()
const;
152 struct FeatureBagImpl;
153 FeatureBagImpl *m_pImpl;
156 bool LoadFromBagInternal(INodeMap *pNodeMap,
bool Verify , GENICAM_NAMESPACE::gcstring_vector *pErrorList = NULL);
157 int64_t StoreToBagInternal(INodeMap *pNodeMap,
const int MaxNumPersistSkriptEntries = -1, GENICAM_NAMESPACE::gcstring_vector *pFeatureFilter = NULL);
159 friend class CFeatureBagger;
163 #define GENAPI_PERSISTENCE_MAGIC "{05D8C294-F295-4dfb-9D01-096BD04049F4}"
166 #define GENAPI_PERSISTENCE_MAGIC_FEATUREBAGGER "{4709CB3C-7322-4460-84C3-DA11DDA09939}"
177 char FirstCharacter =
static_cast<char>(is.peek());
178 while( FirstCharacter ==
'#' )
180 is.ignore(1024,
'\n');
181 FirstCharacter =
static_cast<char>(is.peek());
186#ifndef GENAPI_DONT_USE_DEFAULT_PERSISTENCE_FILE_FORMAT
190 char* pend = Name + strlen( Name );
192 for (; pc < pend && std::isspace( *pc, is.getloc() ); ++pc);
193 for (--pend; pc < pend && std::isspace( *pend, is.getloc() ); --pend);
200 size_t iend =s.length();
202 for (; ibegin < iend && std::isspace( s[ibegin], is.getloc() ); ++ibegin);
203 for (--iend; ibegin < iend; --iend)
205 if (!std::isspace( s[iend], is.getloc() ))
208 if (iend < s.length())
212 s.erase( 0, ibegin );
217 template <
class ForwardIterator,
class T>
218 inline ForwardIterator remove (ForwardIterator first, ForwardIterator last,
const T& val)
220 ForwardIterator result = first;
221 while (first!=last) {
222 if (!(*first == val)) {
244 std::ostringstream originalContent;
245 originalContent << is.rdbuf();
246 is.seekg(std::ios::beg);
247 std::string toBeNormalized(originalContent.str());
249 toBeNormalized.erase(
250 GENAPI_NAMESPACE::remove(toBeNormalized.begin(),
251 toBeNormalized.end(), 13), toBeNormalized.end());
252 std::stringbuf normalizedBuffer(toBeNormalized.c_str());
253 std::istream normalizedStream(&normalizedBuffer);
256 FirstLine.reserve( 128 );
257 GENICAM_NAMESPACE::getline( normalizedStream, FirstLine,
'\n' );
260 if( GENICAM_NAMESPACE::gcstring::_npos() == FirstLine.find(MagicGUID) )
263 if( GENICAM_NAMESPACE::gcstring::_npos() == FirstLine.find(MagicGUID) )
265 throw RUNTIME_EXCEPTION(
"The stream is not a GenApi feature stream since it is missing the magic GUID in the first line");
267 throw RUNTIME_EXCEPTION(
"The stream has been created using the CFeatureBagger class thus must be restored using the CFeatureBagger class as well");
274 Value.reserve( 128 );
275 while (!normalizedStream.eof())
277 GENICAM_NAMESPACE::getline( normalizedStream, Name,
'\t' );
278 if (normalizedStream.fail())
284 Name =
TrimSpace( Name, normalizedStream );
290 CSelectorState *pSelectorState = FeatureBag.AllocateSelector();
297 if (normalizedStream.peek() ==
'{')
299 GENICAM_NAMESPACE::getline( normalizedStream, Value,
'\t' );
300 if (normalizedStream.fail())
304 for (
size_t iassign = Value.find_last_of(
'=' ); iassign != GENICAM_NAMESPACE::gcstring::_npos(); iassign = Value.find_last_of(
'=' ))
306 const size_t iend = Value.find_last_of(
'}');
307 const size_t ibeg = (Value[0] ==
'{') ? 1 : 0;
308 const size_t rhs_len = iend == GENICAM_NAMESPACE::gcstring::_npos() ? iend : iend - iassign - 1;
309 const size_t lhs_len = iassign - ibeg;
312 pSelectorState->AddSelector( selectorName, selectorValue );
313 if (iend != GENICAM_NAMESPACE::gcstring::_npos())
318 GENICAM_NAMESPACE::getline( normalizedStream, Value,
'\t' );
319 if (normalizedStream.fail())
325 GENICAM_NAMESPACE::getline( normalizedStream, Value,
'\n' );
328 FeatureBag.DeleteSelector(pSelectorState);
332 FeatureBag.Push( Name.c_str(), Value.c_str(), pSelectorState );
345 if( !FeatureBag.GetInfo().empty() )
347 os <<
"# GenApi persistence file (version " << GENAPI_VERSION_MAJOR <<
"." << GENAPI_VERSION_MINOR <<
"." << GENAPI_VERSION_SUBMINOR <<
")\n";
348 os <<
"# " << FeatureBag.GetInfo() <<
"\n";
351 CFeatureBag::const_iterator it = FeatureBag.GetBegin(), end = FeatureBag.GetEnd();
358 if ((it->pState)->IsEmpty())
360 os << Name <<
"\t" << Value <<
"\n";
366 (it->pState)->SetFirst();
373 os << (it->pState)->GetNodeName() <<
"=" << (it->pState)->GetNodeValue();
374 }
while ((it->pState)->SetNext());
375 os <<
"}\t" << Value <<
"\n";
387 class GENAPI_DECL const_iterator
399 const_iterator & operator ++ (
void);
400 const_iterator operator ++ (
int);
401 const_iterator & operator += (intptr_t iInc);
402 const_iterator operator + (intptr_t iInc)
const;
403 intptr_t operator - (
const const_iterator &iter)
const;
404 bool operator == (
const const_iterator &iter)
const;
405 bool operator != (
const const_iterator &iter)
const;
423 size_t Bag(INodeMap *pNodeMap,
bool handleDefaultNodeMap =
true,
bool handleUserSets =
false,
bool handleSequencerSets =
false,
const int MaxNumPersistSkriptEntries = -1);
432 bool UnBag(INodeMap *pNodeMap,
bool Verify =
true, GENICAM_NAMESPACE::gcstring_vector *pErrorList = NULL);
439 virtual const_iterator begin(
void)
const;
440 virtual const_iterator end(
void)
const;
441 virtual const CFeatureBag& at(
size_t uiIndex)
const;
442 virtual size_t size(
void)
const;
454 void DeleteAllBags(
void );
463#ifndef GENAPI_DONT_USE_DEFAULT_PERSISTENCE_FILE_FORMAT
470 if( !featureBagger.m_Info.empty() )
472 os <<
"# GenApi CFeatureBagger persistence file (version " << GENAPI_VERSION_MAJOR <<
"." << GENAPI_VERSION_MINOR <<
"." << GENAPI_VERSION_SUBMINOR <<
")\n";
473 os <<
"# " << featureBagger.m_Info <<
"\n";
476 CFeatureBagger::const_iterator it;
477 for (it = featureBagger.begin(); it != featureBagger.end(); it++)
479 os <<
"[" << (*it).GetBagName() <<
"]\n";
498 GENICAM_NAMESPACE::getline( is, FirstLine,
'\n' );
500 bool boCFeatureBagFormatDetected =
false;
501 if( GENICAM_NAMESPACE::gcstring::_npos() == FirstLine.find(MagicGUID) )
504 if( GENICAM_NAMESPACE::gcstring::_npos() == FirstLine.find(MagicGUID) )
506 throw RUNTIME_EXCEPTION(
"The stream is not a GenApi feature stream since it is missing the magic GUID in the first line");
508 boCFeatureBagFormatDetected =
true;
511 std::stringstream currentBagData;
512 if (boCFeatureBagFormatDetected)
514 currentBagData << FirstLine;
521 featureBagger.DeleteAllBags();
523 CFeatureBag *pBag = boCFeatureBagFormatDetected ? &featureBagger.AddBag(
"All") : NULL;
528 GENICAM_NAMESPACE::getline(is, line);
533 if (!line.empty() && (line[0] ==
'['))
535 if (!currentBagData.str().empty())
539 currentBagData >> (*pBag);
541 currentBagData.str(
"");
542 currentBagData.clear();
546 const size_t pos = line.find_first_of(
"]");
548 if( !bagName.empty() )
550 pBag = &featureBagger.AddBag(bagName);
555 currentBagData << line <<
"\n";
558 if (!currentBagData.str().empty() && pBag)
560 currentBagData >> (*pBag);
declspec's to be used for GenApi Windows dll
virtual IBoolean & operator=(bool Value)
Set node value.
Definition IBoolean.h:62
char * TrimSpace(char *Name, std::istream &is)
Helper function cutting off space characters.
Definition Persistence.h:188
virtual void PersistFeature(IValue &item, CSelectorSet *selectorSet=NULL)=0
Stores a feature.
std::istream & EatComments(std::istream &is)
Helper function ignoring lines starting with comment character '#'.
Definition Persistence.h:170
#define GENAPI_PERSISTENCE_MAGIC_FEATUREBAGGER
the magic GUID which indicates that the file is a GenApi stream file created by the CFeatureBagger cl...
Definition Persistence.h:166
#define GENAPI_PERSISTENCE_MAGIC
the magic GUID which indicates that the file or buffer is a GenApi stream created by the CFeatureBag ...
Definition Persistence.h:163
Definition of template CPointer.
Common types used in the public GenApi interface.
Bag holding streamable features of a nodetree.
Definition Persistence.h:56
bool operator==(const CFeatureBag &FeatureBag) const
compares the content of two feature bags
bool LoadFromBag(INodeMap *pNodeMap, bool Verify=true, GENICAM_NAMESPACE::gcstring_vector *pErrorList=NULL)
int64_t StoreToBag(INodeMap *pNodeMap, const int MaxNumPersistSkriptEntries=-1, GENICAM_NAMESPACE::gcstring_vector *pFeatureFilter=NULL)
Stores the streamable nodes to this feature bag.
virtual void PersistFeature(IValue &item, CSelectorSet *selectorSet=NULL)
Stores a feature.
virtual void SetInfo(const GENICAM_NAMESPACE::gcstring &Info)
sets information about the node map
Class use to bag features.
Definition Persistence.h:385
bool UnBag(INodeMap *pNodeMap, bool Verify=true, GENICAM_NAMESPACE::gcstring_vector *pErrorList=NULL)
size_t Bag(INodeMap *pNodeMap, bool handleDefaultNodeMap=true, bool handleUserSets=false, bool handleSequencerSets=false, const int MaxNumPersistSkriptEntries=-1)
Stores the streamable nodes to this feature bags in different device configurations.
virtual void SetInfo(const GENICAM_NAMESPACE::gcstring &Info)
sets information about the node map
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition Pointer.h:50
The set of selectors selecting a given node.
Definition SelectorSet.h:40
A string class which is a clone of std::string.
Definition GCString.h:51
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
Definition GCException.h:246
std::istream & operator>>(std::istream &istr, GENICAM_NAMESPACE::gcstring &str)
Definition GCString.h:245
std::ostream & operator<<(std::ostream &ostr, const GENICAM_NAMESPACE::gcstring &str)
Definition GCString.h:229