ICP  1
labview_xml.h
Go to the documentation of this file.
1 #ifndef LABVIEW_XML
2 #define LABVIEW_XML
3 
4 #include "DAEstatus.h"
5 
6 // indexed by type field
7 static const wchar_t* lv_tags[] = { L"U8", L"U16", L"U32",
8  L"I8", L"I16", L"I32",
9  L"String", L"DBL", L"EW",
10  L"Boolean", L"Path" };
11 static const char* lv_format[] = { "%hu", "%hu", "%u",
12  "%h", "%h", "%d",
13  "%s", "%g", "%d"
14  "%d", "%s" };
15 static const char* lv_defaults[] = { "0", "0", "0",
16  "0", "0", "0",
17  "", "0.0", "0",
18  "0", "" };
19 static const int n_lv = sizeof(lv_tags) / sizeof(wchar_t*);
20 
22 {
23  IXMLDOMDocument *m_pxmldom;
24  struct labview_item
25  {
26  int type;
27  std::vector<std::string> value;
28  int index;
29  labview_item() : type(-1000), index(0) {}
30  };
31  typedef std::map<std::string, labview_item> list_t;
32  typedef std::pair<list_t::iterator,bool> insert_t;
33  typedef list_t::iterator iterator_t;
34  typedef list_t::const_iterator c_iterator_t;
36 
37 public:
38  int loadFromString(BSTR xml_string, DAEstatus& status);
39  int loadFromString(const char* xml_string, DAEstatus& status);
40  int saveToString(std::string& s, DAEstatus& status);
41 // int saveToString(BSTR* bstr, DAEstatus& status);
42 
43  int loadFromFile(const char* filename, DAEstatus& status);
44  int saveToFile(const char* filename, DAEstatus& status);
45 
46  int updateFrom(const LabviewXML& lvxml, DAEstatus& status);
47  int updateFromString(const std::string& xml_string, DAEstatus& status);
48  int updateFromString(const char* xml_chars, DAEstatus& status);
49 
50  int setValue(const char* name, const char* value, DAEstatus& status);
51  int setValue(const char* name, double value, DAEstatus& status);
52  int setValue(const char* name, long value, DAEstatus& status);
53  int setValue(const char* name, int value, DAEstatus& status);
54  int setValue(const char* name, unsigned long value, DAEstatus& status);
55  int setValue(const char* name, unsigned int value, DAEstatus& status);
56  int setValue(const char* name, __int64 value, DAEstatus& status);
57  int setValue(const char* name, const std::vector<std::string>& value, DAEstatus& status);
58 
59  int getValue(const char* name, char* value, int max_len, bool write_null, DAEstatus& status);
60  int getValue(const char* name, std::string& value, DAEstatus& status);
61  int getValue(const char* name, double& value, DAEstatus& status);
62  int getValue(const char* name, float& value, DAEstatus& status);
63  int getValue(const char* name, long& value, DAEstatus& status);
64  int getValue(const char* name, int& value, DAEstatus& status);
65  int getValue(const char* name, __int64& value, DAEstatus& status);
66  int getValue(const char* name, std::vector<std::string>& value, DAEstatus& status);
67 
68  std::string valueAsString(const char* name, DAEstatus& status);
69  LabviewXML(DAEstatus& status) : m_pxmldom(0) { DomFromCOM(status); }
70  int close() { if (m_pxmldom != NULL) { m_pxmldom->Release(); m_pxmldom = 0; } return 1; }
71  ~LabviewXML() { close(); }
72 
73 protected:
74  int processElements(int type, bool reading, DAEstatus& status);
75  int processAllElements(bool reading, DAEstatus& status);
76  int DomFromCOM(DAEstatus& status);
77  int setISO8859Encoding(DAEstatus& status);
78 
79 private:
80  LabviewXML();
81 };
82 
83 #endif
int loadFromString(BSTR xml_string, DAEstatus &status)
std::string valueAsString(const char *name, DAEstatus &status)
std::map< std::string, labview_item > list_t
Definition: labview_xml.h:31
int setValue(const char *name, const char *value, DAEstatus &status)
int loadFromFile(const char *filename, DAEstatus &status)
int updateFromString(const std::string &xml_string, DAEstatus &status)
int setISO8859Encoding(DAEstatus &status)
list_t m_list
Definition: labview_xml.h:35
int getValue(const char *name, char *value, int max_len, bool write_null, DAEstatus &status)
static const char * lv_defaults[]
Definition: labview_xml.h:15
int updateFrom(const LabviewXML &lvxml, DAEstatus &status)
int DomFromCOM(DAEstatus &status)
int saveToString(std::string &s, DAEstatus &status)
LabviewXML(DAEstatus &status)
Definition: labview_xml.h:69
static const wchar_t * lv_tags[]
Definition: labview_xml.h:7
static const char * lv_format[]
Definition: labview_xml.h:11
std::pair< list_t::iterator, bool > insert_t
Definition: labview_xml.h:32
int saveToFile(const char *filename, DAEstatus &status)
int close()
Definition: labview_xml.h:70
int processElements(int type, bool reading, DAEstatus &status)
list_t::const_iterator c_iterator_t
Definition: labview_xml.h:34
int processAllElements(bool reading, DAEstatus &status)
std::vector< std::string > value
Definition: labview_xml.h:27
static const int n_lv
Definition: labview_xml.h:19
list_t::iterator iterator_t
Definition: labview_xml.h:33
IXMLDOMDocument * m_pxmldom
Definition: labview_xml.h:23