fastdo  0.6.8
elem_utils.hpp
浏览该文件的文档.
1 #ifndef __EIEN__EIENML__ELEMENTUTILS_HPP__
2 #define __EIEN__EIENML__ELEMENTUTILS_HPP__
3 
7 namespace eienml
8 {
9 
12 {
17 };
18 
21 {
27 };
28 // 相关宏 ----------------------------------------------------
29 /* 给指针指的空间赋值 */
30 #define AssignToPointer( ptr, val ) if ( ptr ) *( ptr ) = ( val )
31 
32 #define DEFINE_NEWDOC_FUNC( cls ) DEFINE_NEWOBJ_FUNC( cls, eienml::Document )
33 #define DEFINE_NEWBLOCK_FUNC( cls ) DEFINE_NEWOBJ_FUNC( cls, eienml::Block )
34 #define DEFINE_NEWELEM_FUNC( cls ) DEFINE_NEWOBJ_FUNC( cls, eienml::Element )
35 #define DEFINE_NEWTEXT_FUNC( cls ) DEFINE_NEWOBJ_FUNC( cls, eienml::TextNode )
36 #define DEFINE_NEWNODE_FUNC( cls ) DEFINE_NEWOBJ_FUNC( cls, eienml::Node )
37 #define DEFINE_NEWOBJ_FUNC( cls, ret )\
38 inline static ret * NewInstance( void )\
39 {\
40  return new cls();\
41 }
42 // 指针转化
43 #define ClassObj( cls, p ) ( static_cast<cls *>( p ) )
44 #define TextNodeObj( p ) ClassObj( eienml::TextNode, ( p ) )
45 #define BlockObj( p ) ClassObj( eienml::Block, ( p ) )
46 #define ElementObj( p ) ClassObj( eienml::Element, ( p ) )
47 #define DocumentObj( p ) ClassObj( eienml::Document, ( p ) )
48 // 相关类 ----------------------------------------------------
49 class ElemPackage;
50 class Element;
51 class Document;
52 
55 {
56 public:
58  void delInstance( void );
59  virtual winux::AnsiString asStr( int procType = ProcType_Raw );
60  virtual void doWork( void );
61  // 属性
62  ElemPackage const * getPackage( void ) const;
63  void setPackage( ElemPackage const * package );
64  Element * getParent( void ) const;
65  void setParent( Element * element );
66  Document * getDocument( void ) const;
67  NodeType getType( void ) const;
68 protected:
69  Node( void );
70  virtual ~Node( void );
71  ElemPackage const * package; // 指向元素包
72  Element * parent; // 父节点
73  NodeType type;
74 };
75 
77 class EIENML_DLL TextNode : public Node
78 {
79 public:
81  virtual winux::AnsiString asStr( int procType = ProcType_Raw );
82  virtual void doWork( void );
83  winux::AnsiString getValue( void ) const;
84  void setValue( winux::AnsiString const & value );
85 protected:
86  TextNode( void );
87  virtual ~TextNode( void );
88  winux::AnsiString value;
89 public:
90  winux::AnsiString rawTextNode;
91 };
92 
94 class EIENML_DLL Block : public Node
95 {
96 public:
98  virtual winux::AnsiString asStr( int procType = ProcType_Raw );
99 protected:
100  Block( void );
101  ~Block( void );
102 public:
103  winux::AnsiString blockTag;
104  winux::AnsiString blockContent;
105  winux::AnsiString rawBlock;
106 };
107 
108 typedef std::map<winux::AnsiString, winux::AnsiString> Attributes;
109 typedef std::vector<Node *> NodeArray;
110 typedef std::vector<Block *> BlockArray;
111 typedef std::vector<Element *> ElementArray;
112 
114 class EIENML_DLL Element : public Node
115 {
116 public:
118  virtual winux::AnsiString childAsStr( int procType = ProcType_Raw );
119  virtual void doChildWork( void );
124  bool addTextToLast( winux::AnsiString const & str, TextNode * * p = NULL );
125  bool addChild( Node * element );
126  bool hasChildren( void );
127  void getElements( ElementArray * arr, winux::AnsiString const & tagName );
128  void getBlocks( BlockArray * arr, winux::AnsiString const & blockTag );
129  virtual winux::AnsiString asStr( int procType = ProcType_Raw );
130  virtual void doWork( void );
131  bool hasAttr( winux::AnsiString const & name ) const;
132  winux::AnsiString getAttr( winux::AnsiString const & name ) const;
133  void setAttr( winux::AnsiString const & name, winux::AnsiString const & value );
134  void delAttr( winux::AnsiString const & name );
135 
136  NodeArray & getChildren( void );
137  Attributes & getAttributes( void );
138  void setAttributes( Attributes const & attrs );
139  bool isOdd( void ) const;
140 protected:
141  Element( void );
142  virtual ~Element( void );
143  virtual winux::AnsiString replaceProc( void );
144  virtual winux::AnsiString treeProc( void );
145 
146  Attributes attrs;
147  bool odd;
148  NodeArray children;
149 public:
150  winux::AnsiString raw1;
151  winux::AnsiString raw2;
152  winux::AnsiString tagName;
153  winux::AnsiString defAttr;
154 };
155 
158 {
159 public:
161  OddElement( void )
162  {
163  this->odd = true;
164  }
165 };
166 
169 {
170 public:
172  virtual winux::AnsiString asStr( int procType = ProcType_Raw );
173  virtual void doWork( void );
174 protected:
175  Document( void );
176  virtual ~Document( void );
177 };
178 
179 }
180 
181 
182 #endif // __EIEN__EIENML__ELEMENTUTILS_HPP__
XString< char > AnsiString
Definition: utilities.hpp:212
std::vector< Block * > BlockArray
Definition: elem_utils.hpp:110
std::vector< Element * > ElementArray
Definition: elem_utils.hpp:111
单独元素类(没有尾)
Definition: elem_utils.hpp:157
块节点类
Definition: elem_utils.hpp:94
STL namespace.
#define DEFINE_NEWDOC_FUNC(cls)
Definition: elem_utils.hpp:32
NodeType
节点类型
Definition: elem_utils.hpp:11
去掉元素tag,输出非元素部分
Definition: elem_utils.hpp:25
#define EIENML_DLL
Definition: eienml.hpp:19
元素节点类
Definition: elem_utils.hpp:114
std::vector< Node * > NodeArray
Definition: elem_utils.hpp:109
不处理,原始内容
Definition: elem_utils.hpp:22
#define DEFINE_NEWELEM_FUNC(cls)
Definition: elem_utils.hpp:34
简单处理,输出符合规则的内容
Definition: elem_utils.hpp:23
ProcType
元素处理种类
Definition: elem_utils.hpp:20
展现树形结构
Definition: elem_utils.hpp:24
#define DEFINE_NEWNODE_FUNC(cls)
Definition: elem_utils.hpp:36
文本节点类
Definition: elem_utils.hpp:77
#define DEFINE_NEWTEXT_FUNC(cls)
Definition: elem_utils.hpp:35
节点基类
Definition: elem_utils.hpp:54
标签式语言支持库
Definition: elem_package.hpp:5
#define DEFINE_NEWBLOCK_FUNC(cls)
Definition: elem_utils.hpp:33
替换处理,输出转换后的内容
Definition: elem_utils.hpp:26
std::map< winux::AnsiString, winux::AnsiString > Attributes
Definition: elem_utils.hpp:108
跨平台基础功能库
Definition: archives.hpp:7