FEDM_XmlParser_IReader.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |       FEDM_XmlParser_IReader.cpp                                      |
00004 |                                                       |
00005 ---------------------------------------------------------
00006 
00007 Copyright � 2008-2011 FEIG ELECTRONIC GmbH, All Rights Reserved.
00008                                                 Lange Strasse 4
00009                                                 D-35781 Weilburg
00010                                                 Federal Republic of Germany
00011                                                 phone    : +49 6471 31090
00012                                                 fax      : +49 6471 310999
00013                                                 e-mail   : obid-support@feig.de
00014                                                 Internet : http://www.feig.de
00015                                         
00016 Author                  :       Markus Hultsch
00017 Begin                   :       23.01.2008
00018 Version                 :       04.00.02 / 22.08.2011 / M. Hultsch
00019 Operation Systems       :       independent
00020 Function                        :       abstract xml reader class for basic parser API
00021 
00022 OBID� and OBID i-scan� are registered Trademarks of FEIG ELECTRONIC GmbH.
00023 Linux� is a registered trademark of Linus Torvalds.
00024 Microsoft� and Windows� are registered trademarks of Microsoft Corporation.
00025 */
00026 
00027 
00028 
00029 //#############################
00030 //      I N C L U D E S
00031 //#############################
00032 #include "FEDM_XmlParser_IReader.h"                             // public include file of library
00033 #include "FEDM_XmlParser_Base.h"
00034 
00035 
00036 //#######################################################################################
00037 //      class FEDM_XmlParser_Reader
00038 //#######################################################################################
00039 FEDM_XmlParser_Reader::FEDM_XmlParser_Reader(void)
00040 {
00041         m_pXmlParser = NULL;
00042 }
00043 
00044 FEDM_XmlParser_Reader::~FEDM_XmlParser_Reader(void)
00045 {
00046 }
00047 
00048 //#####################################################################################
00049 // serialization functions
00050 //#####################################################################################
00051 
00052 /***************************************************************************
00053   Begin         :       23.01.2008
00054   Version       :       04.00.02 / 22.08.2011 / M. Hultsch
00055 
00056   Function              :       read xml file-header
00057 
00058   Parameters    :       FEDM_XML_TREEITEM* root - parent element
00059                                         const char* szVendor    - name of vendor
00060 
00061   Return value  :       FEDM_OK or error code (<0)
00062 
00063 ***************************************************************************/
00064 int FEDM_XmlParser_Reader::SerializeHeaderIn(FEDM_XML_TREEITEM* root, const char* szVendor)
00065 {
00066         if(root == NULL)
00067         {
00068                 m_pXmlParser->SetLastError(FEDM_ERROR_NULL_POINTER);
00069                 return FEDM_ERROR_NULL_POINTER;
00070         }
00071 
00072         char    cValue[512];
00073         wchar_t wcTmp[FEDM_MAX_TEXT_SIZE+2];
00074         wstring sTmp;
00075         unsigned int uiValue[3];
00076         FEDM_XML_TREEITEM* child        = NULL;
00077         FEDM_XML_TREEITEM* parent       = NULL;
00078 
00079         
00080         // #####################################################
00081         // header tag
00082         child = FindTag(FEDM_XML_TAG_FILE_HDR_UC, (unsigned int)1);
00083         if(child == NULL)
00084         {
00085                 DeleteXmlTree(); // clean up
00086                 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00087                 return m_pXmlParser->GetLastError();
00088         }
00089         AddTagItem(root, child);
00090         parent = child;
00091 
00092         // header tag document type
00093         child = FindTag(FEDM_XML_TAG_DOC_TYPE_UC, (unsigned int)2);
00094         if(child == NULL)
00095         {
00096                 DeleteXmlTree(); // clean up
00097                 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00098                 return m_pXmlParser->GetLastError();
00099         }
00100         if(child->sValue.length() < FEDM_MAX_TEXT_SIZE)
00101         {
00102                 for (unsigned int i = 0; i < child->sValue.length(); i++)
00103                         m_pXmlParser->m_XmlHeader.szDocType[i] = (char)(child->sValue.c_str())[i];
00104         }
00105         AddTagItem(parent, child);
00106 
00107         // header tag document version
00108         child = FindTag(FEDM_XML_TAG_DOC_VERSION_UC, (unsigned int)2, true);
00109         if(child == NULL)
00110         {
00111                 DeleteXmlTree(); // clean up
00112                 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00113                 return m_pXmlParser->GetLastError();
00114         }
00115         memset(uiValue, 0, 3);
00116 #if defined(_MSC_VER)
00117         swscanf(child->sValue.c_str(), L"%S", cValue);
00118 #else
00119         swscanf(child->sValue.c_str(), L"%s", cValue);
00120 #endif
00121         sscanf(cValue, "%u.%u", &uiValue[0], &uiValue[1]);
00122         m_pXmlParser->m_XmlHeader.uiDocVersion = (((unsigned char)uiValue[0]) << 8) + (unsigned char)uiValue[1];
00123         AddTagItem(parent, child);
00124 
00125         // header tag vendor
00126         child = FindTag(FEDM_XML_TAG_VENDOR_UC, (unsigned int)2, true);
00127         if(child == NULL)
00128         {
00129                 DeleteXmlTree(); // clean up
00130                 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00131                 return m_pXmlParser->GetLastError();
00132         }
00133         if(strlen(szVendor) > 0)
00134         {
00135 #if defined(__BORLANDC__) || defined(_MSC_VER)
00136                 #if _MSC_VER <= 1200
00137                 swprintf(wcTmp, L"%S", szVendor);
00138                 #else
00139                         #if defined(_WIN32_WCE)
00140                 swprintf(wcTmp, L"%S", szVendor);
00141                         #else
00142                 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"%S", szVendor);
00143                         #endif
00144                 #endif
00145 #else
00146                 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"%s", szVendor);
00147 #endif
00148         }
00149         else
00150         {
00151 #if defined(__BORLANDC__) || defined(_MSC_VER)
00152                 #if _MSC_VER <= 1200
00153                 swprintf(wcTmp, L"FEIG ELECTRONIC");
00154                 #else
00155                         #if defined(_WIN32_WCE)
00156                 swprintf(wcTmp, L"FEIG ELECTRONIC");
00157                         #else
00158                 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"FEIG ELECTRONIC");
00159                         #endif
00160                 #endif
00161 #else
00162                 swprintf(wcTmp, FEDM_MAX_TEXT_SIZE+2, L"FEIG ELECTRONIC");
00163 #endif
00164         }
00165         sTmp = wcTmp;
00166         if(child->sValue != wcTmp)
00167         {
00168                 delete child;
00169                 DeleteXmlTree(); // clean up
00170                 m_pXmlParser->SetLastError(FEDM_XML_ERROR_DOC_FILE_TYPE);
00171                 return m_pXmlParser->GetLastError();            
00172         }
00173         if(strlen(szVendor) > 0)
00174                 strcpy(m_pXmlParser->m_XmlHeader.szVendor, szVendor);
00175         else
00176                 strcpy(m_pXmlParser->m_XmlHeader.szVendor, "FEIG ELECTRONIC");
00177         AddTagItem(parent, child);
00178 
00179         // header tag fedm version
00180         child = FindTag(FEDM_XML_TAG_FEDM_VERSION_UC, (unsigned int)2, true);
00181         if(child == NULL)
00182         {
00183                 DeleteXmlTree(); // clean up
00184                 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00185                 return m_pXmlParser->GetLastError();
00186         }
00187         memset(uiValue, 0, 3);
00188 #if defined(_MSC_VER)
00189         swscanf(child->sValue.c_str(), L"%S", cValue);
00190 #else
00191         swscanf(child->sValue.c_str(), L"%s", cValue);
00192 #endif
00193         sscanf(cValue, "%02u.%02u.%02u", &uiValue[0], &uiValue[1], &uiValue[2]);
00194         m_pXmlParser->m_XmlHeader.uiFedmVersion = (((unsigned char)uiValue[0]) << 16) + (((unsigned char)uiValue[1]) << 8) + (unsigned char)uiValue[2];
00195         AddTagItem(parent, child);
00196 
00197         // header tag comment
00198         child = FindTag(FEDM_XML_TAG_COMMENT_UC, (unsigned int)2, true);
00199         if(child == NULL)
00200         {
00201                 DeleteXmlTree(); // clean up
00202                 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00203                 return m_pXmlParser->GetLastError();
00204         }
00205         if(child->sValue.length() < FEDM_MAX_TEXT_SIZE)
00206         {
00207                 for (unsigned int i = 0; i < child->sValue.length(); i++)
00208                         m_pXmlParser->m_XmlHeader.szComment[i] = (char)(child->sValue.c_str())[i];
00209         }
00210         AddTagItem(parent, child);
00211 
00212         // header tag checksum
00213         child = FindTag(FEDM_XML_TAG_CRC_UC, (unsigned int)2, true);
00214         if(child == NULL)
00215         {
00216                 DeleteXmlTree(); // clean up
00217                 m_pXmlParser->SetLastError(m_pXmlParser->GetLastError());
00218                 return m_pXmlParser->GetLastError();
00219         }
00220 #if defined(_MSC_VER)
00221         swscanf(child->sValue.c_str(), L"%S", cValue);
00222 #else
00223         swscanf(child->sValue.c_str(), L"%s", cValue);
00224 #endif
00225         sscanf(cValue, "%u", &m_pXmlParser->m_XmlHeader.uiCrc);
00226         AddTagItem(parent, child);
00227 
00228         m_pXmlParser->SetLastError(FEDM_OK);
00229         return m_pXmlParser->GetLastError();
00230 }
00231 
00232 /***************************************************************************
00233   Begin         :       23.01.2008
00234   Version       :       03.00.00 / 23.01.2008 / M. Hultsch
00235 
00236   Function              :       query at index one attribute (name and value) from tags attribute list
00237 
00238   Parameters    :       FEDM_XML_TREEITEM* item - pointer to tree item
00239                                         int iIndex                              - index in attribute list
00240                                         string sAttrib                  - attribute name
00241                                         string& sValue                  - attribute value
00242 
00243   Return value  :       
00244 
00245 ***************************************************************************/
00246 int FEDM_XmlParser_Reader::GetTagAttrib(        FEDM_XML_TREEITEM* item,
00247                                                                                         int iIndex, 
00248                                                                                         string& sAttrib, 
00249                                                                                         string& sValue)
00250 {
00251         if(item == NULL)
00252         {
00253                 m_pXmlParser->SetLastError(FEDM_ERROR_NULL_POINTER);
00254                 return FEDM_ERROR_NULL_POINTER;
00255         }
00256         
00257         if((int)item->aAttribList.size() <= iIndex)
00258         {
00259                 m_pXmlParser->SetLastError(FEDM_XML_ERROR_NO_TAG_ATTRIBUTE);
00260                 return m_pXmlParser->GetLastError();
00261         }
00262 
00263         char cBuffer[256];
00264 
00265         // attribute name: convert UNICODE to char
00266         if(item->aAttribList[iIndex]->sAttribute.size() > 256)
00267         {
00268                 m_pXmlParser->SetLastError(FEDM_ERROR_STRING_LENGTH);
00269                 return m_pXmlParser->GetLastError();    
00270         }
00271 
00272         // attribute value: convert UNICODE to char
00273         if(item->aAttribList[iIndex]->sValue.size() > 256)
00274         {
00275                 m_pXmlParser->SetLastError(FEDM_ERROR_STRING_LENGTH);
00276                 return m_pXmlParser->GetLastError();    
00277         }
00278 
00279 #if defined(__BORLANDC__) || defined(_MSC_VER)
00280         sprintf(cBuffer, "%S", item->aAttribList[iIndex]->sAttribute.c_str());
00281 #else
00282         sprintf(cBuffer, "%S", (const char*)item->aAttribList[iIndex]->sAttribute.c_str());
00283 #endif
00284         sAttrib = cBuffer;
00285 
00286 #if defined(__BORLANDC__) || defined(_MSC_VER)
00287         sprintf(cBuffer, "%S", item->aAttribList[iIndex]->sValue.c_str());
00288 #else
00289         sprintf(cBuffer, "%S", (const char*)item->aAttribList[iIndex]->sValue.c_str());
00290 #endif
00291         sValue = cBuffer;
00292 
00293         m_pXmlParser->SetLastError(FEDM_OK);
00294         return m_pXmlParser->GetLastError();
00295 }
00296 


maggie_rfid_drivers
Author(s): Raul Perula-Martinez
autogenerated on Mon Sep 14 2015 03:05:29