Persistence.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2007 by National Instruments
00003 //  Project: GenApi
00004 //  Author:  Eric Gross
00005 //  $Header$
00006 //
00007 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00008 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00009 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00010 //  (http://www.genicam.org) for a full copy.
00011 //
00012 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00013 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00014 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00015 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00016 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00017 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00018 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00019 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00020 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00021 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00022 //  POSSIBILITY OF SUCH DAMAGE.
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     // note: this method must be inlined because it uses istream in the parameter list
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     // note: this method must be inlined because it uses istream in the parameter list
00126     // note: May not be used as inline if called against a library where it is already compiled.
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         // Check the magic
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())  // if reading from stream failed -> stop reading!
00152                 break;
00153 
00154             GENICAM_NAMESPACE::getline(is, Value);
00155             if (is.fail())  // if reading from stream failed -> stop reading!
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     // note: this method must be inlined because it uses ostream in the parameter list
00170     // note: May not be used as inline if called against a library where it is already compiled.
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


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06