Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030 #ifndef _GENICAM_PERSISTENCE_H
00031 #define _GENICAM_PERSISTENCE_H
00032
00033 #include <GenApi/Types.h>
00034 #include <GenApi/Pointer.h>
00035 #include <GenApi/GenApiDll.h>
00036 #include <list>
00037 #include <iostream>
00038
00039 using namespace GENICAM_NAMESPACE;
00040
00041 namespace GENAPI_NAMESPACE
00042 {
00043
00045 interface GENAPI_DECL_ABSTRACT IPersistScript
00046 {
00048 virtual void SetInfo(gcstring &Info) = 0;
00049
00051 virtual void PersistFeature(IValue& item) = 0;
00052 };
00053
00055 class GENAPI_DECL CFeatureBag : public IPersistScript
00056 {
00057 public:
00059 virtual void SetInfo(gcstring &Info);
00060
00062 virtual void PersistFeature(IValue& item);
00063
00068
00072 bool LoadFromBag(INodeMap *pNodeMap, bool Verify = true, gcstring_vector *pErrorList = NULL);
00073
00079 int64_t StoreToBag(INodeMap *pNodeMap, const int MaxNumPersistSkriptEntries = -1 );
00080
00082 bool operator==(const CFeatureBag &FeatureBag) const;
00083
00084 gcstring ToString();
00085
00087 friend std::istream& operator >>(std::istream &is, CFeatureBag &FeatureBag);
00088
00090 friend std::ostream& operator <<(std::ostream &os, const CFeatureBag &FeatureBag);
00091
00092 private:
00094 gcstring_vector m_Names;
00095
00097 gcstring_vector m_Values;
00098
00100 gcstring m_Info;
00101 };
00102
00104 #define GENAPI_PERSISTENCE_MAGIC "{05D8C294-F295-4dfb-9D01-096BD04049F4}"
00105
00107
00108 inline std::istream& EatComments(std::istream &is)
00109 {
00110 if( is.eof() )
00111 return is;
00112
00113 char FirstCharacter;
00114 FirstCharacter = (char)is.peek();
00115
00116 while( FirstCharacter == '#' )
00117 {
00118 is.ignore(1024, '\n');
00119 FirstCharacter = (char)is.peek();
00120 }
00121 return is;
00122 }
00123
00125
00126
00127 inline std::istream& operator >>(std::istream &is, CFeatureBag &FeatureBag)
00128 {
00129 if( is.eof() )
00130 throw RUNTIME_EXCEPTION("The stream is eof");
00131
00132 FeatureBag.m_Names.clear();
00133 FeatureBag.m_Values.clear();
00134
00135 const int BufferSize = 1024;
00136 char Buffer[BufferSize] = {0};
00137 char Name[BufferSize] = {0};
00138 gcstring Value("");
00139
00140
00141 is.getline(Buffer, BufferSize, '\n');
00142 gcstring FirstLine(Buffer);
00143 gcstring MagicGUID(GENAPI_PERSISTENCE_MAGIC);
00144 if( gcstring::_npos() == FirstLine.find(MagicGUID) )
00145 throw RUNTIME_EXCEPTION("The stream is not a GenApi feature stream since it is missing the magic GUID in the first line");
00146
00147 EatComments( is );
00148 while( !is.eof() )
00149 {
00150 is.getline(Name, BufferSize, '\t');
00151 if (is.fail())
00152 break;
00153
00154 GENICAM_NAMESPACE::getline(is, Value);
00155 if (is.fail())
00156 break;
00157
00158 FeatureBag.m_Names.push_back(Name);
00159 FeatureBag.m_Values.push_back(Value);
00160
00161 Name[0] = '\0';
00162 Value = "";
00163 EatComments( is );
00164 }
00165 return is;
00166 }
00167
00169
00170
00171 inline std::ostream& operator <<(std::ostream &os, const CFeatureBag &FeatureBag)
00172 {
00173 os << "# " GENAPI_PERSISTENCE_MAGIC "\n";
00174 os << "# GenApi persistence file (version " << GENAPI_VERSION_MAJOR << "." << GENAPI_VERSION_MINOR << "." << GENAPI_VERSION_SUBMINOR << ")\n";
00175 os << "# " << FeatureBag.m_Info << "\n";
00176
00177 gcstring_vector::const_iterator pName = FeatureBag.m_Names.begin();
00178 gcstring_vector::const_iterator pValue = FeatureBag.m_Values.begin();
00179 assert(FeatureBag.m_Names.size() == FeatureBag.m_Values.size());
00180 if (FeatureBag.m_Names.size() == FeatureBag.m_Values.size())
00181 {
00182 const gcstring_vector::const_iterator endNames = FeatureBag.m_Names.end();
00183 for ( ; pName != endNames; ++pName, ++pValue)
00184 {
00185 gcstring Name(*pName);
00186 gcstring Value(*pValue);
00187 os << Name << "\t" << Value << "\n";
00188 }
00189 }
00190
00191 return os;
00192 }
00193
00194 }
00195
00196 #endif //_GENICAM_PERSISTENCE_H