EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
FUX.h
1 // -*- c++ -*-
2 
3 #ifndef _FUX_H_
4 #define _FUX_H_
5 
6 // system
7 #include <stdio.h>
8 
9 // tools
10 #include "tools/ToolsConfig.h"
11 #include "tools/NoCopy.h"
12 
13 #define FUX_XERCES
14 
15 // Check ChannelArchiver/make.cfg for FUX_XERCES and required link commands
16 
40 class FUX {
41 
42 public:
43 
45  FUX();
46 
48  ~FUX();
49 
51  class Element
52  {
53  public:
58  Element(Element *parent, const stdString &name);
59 
64  Element(Element *parent, const stdString &name, const stdString &value);
65 
70  Element(Element *parent, const char *name, const char *format, ...)
71  __attribute__ ((format (printf, 4, 5)));
72 
74  ~Element();
75 
77  const stdString &getName() const
78  { return name; }
79 
81  const stdString &getValue() const
82  { return value; }
83 
86  { return parent; }
87 
89  stdList<Element *> &getChildren()
90  { return children; }
91 
93  void append(const char *text, size_t len)
94  { value.append(text, len); }
95 
97  Element *find(const char *name);
98 
99  private:
100  PROHIBIT_DEFAULT_COPY(Element);
101  Element *parent;
102  stdString name;
103  stdString value;
104 
106  stdList<Element *> children;
107  };
108 
109  stdString DTD;
110 
116  Element *parse(const char *file_name);
117 
119  void clear()
120  {
121  setDoc(0);
122  }
123 
125  void setDoc(Element *doc);
126 
128  static void indent(FILE *f, int depth);
129 
137  void dump(FILE *f);
138 
139 private:
140 
141  PROHIBIT_DEFAULT_COPY(FUX);
142 
143 #ifdef FUX_XERCES
144  friend class FUXContentHandler;
145  friend class FUXErrorHandler;
146 #endif
147 
148  Element *root;
149  Element *current;
150  bool inside_tag;
151 
152  static void start_tag(void *data, const char *el, const char **attr);
153  static void text_handler(void *data, const char *s, int len);
154  static void end_tag(void *data, const char *el);
155  void dump_element(FILE *f, Element *e, int depth);
156 };
157 
158 #endif
Element(Element *parent, const stdString &name)
Create new, empty element.
The f.u.XML helper class.
Definition: FUX.h:40
void clear()
Clear/delete the current document.
Definition: FUX.h:119
Element * parse(const char *file_name)
Parse the given XML file into the FUX tree.
~Element()
Destructor.
const stdString & getName() const
Definition: FUX.h:77
Element * getParent()
Definition: FUX.h:85
stdList< Element * > & getChildren()
Definition: FUX.h:89
Element * find(const char *name)
const stdString & getValue() const
Definition: FUX.h:81
void dump(FILE *f)
Dumps the FUX document.
stdString DTD
The DTD. Set for dump().
Definition: FUX.h:109
static void indent(FILE *f, int depth)
Add indentation to the file.
One element in the FUX tree.
Definition: FUX.h:51
FUX()
Constructor.
void setDoc(Element *doc)
Set the document.
void append(const char *text, size_t len)
Append text to value.
Definition: FUX.h:93
~FUX()
Destructor.
__attribute__((format(printf, 4, 5)))
Create Element, using printf-style format and args for value.