DataDirector API
lmx_utils.h
Go to the documentation of this file.
1 /*! \file lmx_utils.h
2 
3  \par Copyright Information
4 
5  Copyright (c) 2012 The DiSTI Corporation.<br>
6  11301 Corporate Blvd; Suite 100<br>
7  Orlando, Florida 32817<br>
8  USA<br>
9  <br>
10  All rights reserved.<br>
11 
12  This Software contains proprietary trade secrets of DiSTI and may not be
13 reproduced, in whole or part, in any form, or by any means of electronic,
14 mechanical, or otherwise, without the written permission of DiSTI. Said
15 permission may be derived through the purchase of applicable DiSTI product
16 licenses which detail the distribution rights of this content and any
17 Derivative Works based on this or other copyrighted DiSTI Software.
18 
19  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
20 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
21 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
22 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
24 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
25 
26  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
27 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
28 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
29 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
30 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
31 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
32 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
33 EXCEED FIVE DOLLARS (US$5.00).
34 
35  The aforementioned terms and restrictions are governed by the laws of the
36 State of Florida and the United States of America.
37 
38 */
39 
40 #ifndef _lmx_utils_h
41 #define _lmx_utils_h
42 
43 #include "lmxtypes.h"
44 #include "lmxparse.h"
45 
46 /** read an XML into an LMX generated XML binding class
47  * \param xmlBind LMX generated XML binding class to receive data on success
48  * \param fname filname of XML file to read (!=NULL)
49  * \param errMsg [out] receives error msg on failure
50  * \return true on success else false
51  */
52 template< class T > static bool ReadXMLFile( T &xmlBind, const char *fname, std::string &errMsg )
53 {
54  bool success = false;
55 
56  // try to open file
57  lmx::c_xml_reader_file xmlReader( fname );
58  if( xmlReader.is_open() )
59  {
60  // try to read file
61  success = ( lmx::ELMX_OK == xmlBind.unmarshal( xmlReader ) );
62  if( !success )
63  {
64  // get error msg
65  std::string readerError;
66  xmlReader.get_error_message( &readerError );
67 
68  // format err msg
69  errMsg = "Error reading file \"";
70  errMsg += fname;
71  errMsg += "\" :\n";
72  errMsg += readerError + '\n';
73  }
74  }
75  else // could not open file
76  {
77  errMsg = "Error opening file \"";
78  errMsg += fname ;
79  errMsg += "\"\n";
80  }
81 
82  return( success );
83 }
84 
85 /** read an XML into an LMX generated XML binding class
86  * \param xmlBind LMX generated XML binding class to receive data on success
87  * \param data Pointer to character buffer
88  * \param length Length of the buffer
89  * \param errMsg [out] receives error msg on failure
90  * \return true on success else false
91  */
92 template< class T > static bool ReadXMLData( T &xmlBind, const char *data,unsigned int length,std::string &errMsg )
93 {
94  bool success = false;
95 
96  lmx::c_xml_reader_memory xmlReader(data,length);
97 
98  // try to read data
99  success = ( lmx::ELMX_OK == xmlBind.unmarshal( xmlReader ) );
100  if( !success )
101  {
102  // get error msg
103  std::string readerError;
104  xmlReader.get_error_message( &readerError );
105 
106  // format err msg
107  errMsg = "Error parsing metadata: \n";
108  errMsg += readerError + '\n';
109  }
110 
111  return( success );
112 }
113 
114 
115 #endif