1 |
Douglas Thrift |
276 |
// Iffy |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#ifndef _Tag_hpp_ |
8 |
|
|
#define _Tag_hpp_ |
9 |
|
|
|
10 |
douglas |
313 |
#include "Iffy.hpp" |
11 |
|
|
|
12 |
douglas |
309 |
#ifdef MENES_PRAGMA_ONCE |
13 |
|
|
#pragma once |
14 |
|
|
#endif |
15 |
|
|
|
16 |
Douglas Thrift |
276 |
enum TagType { OPEN, CLOSE, STANDALONE }; |
17 |
|
|
|
18 |
|
|
class Tag |
19 |
|
|
{ |
20 |
|
|
private: |
21 |
|
|
TagType type; |
22 |
|
|
ext::String name; |
23 |
|
|
ios::String attributes; |
24 |
|
|
ext::String lower(const ext::String& string); |
25 |
|
|
public: |
26 |
douglas |
288 |
Tag() : type(STANDALONE) {} |
27 |
Douglas Thrift |
276 |
Tag(const ext::String& segment); |
28 |
douglas |
294 |
Tag(TagType type, const ext::String& name) : type(type), name(name) {} |
29 |
Douglas Thrift |
276 |
Tag& operator=(TagType type) { this->type = type; return *this; } |
30 |
Douglas Thrift |
277 |
Tag& operator=(const ext::String& name) { this->name = name; return *this; } |
31 |
Douglas Thrift |
276 |
bool operator==(TagType type) const { return this->type == type; } |
32 |
|
|
bool operator==(const ext::String& name) const { return this->name == name; } |
33 |
Douglas Thrift |
277 |
bool operator!=(TagType type) const { return this->type != type; } |
34 |
|
|
bool operator!=(const ext::String& name) const { return this->name != name; } |
35 |
|
|
operator TagType() const { return type; } |
36 |
|
|
operator ext::String() const { return name; } |
37 |
Douglas Thrift |
276 |
// friends: |
38 |
|
|
friend ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Tag& tag); |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
|
inline ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Tag& tag) |
42 |
|
|
{ |
43 |
Douglas Thrift |
277 |
pout << (tag == CLOSE ? "</" : "<") << tag.name; |
44 |
|
|
|
45 |
|
|
if (tag != CLOSE) pout << tag.attributes; |
46 |
|
|
|
47 |
|
|
return pout << (tag == STANDALONE ? "/>" : ">"); |
48 |
Douglas Thrift |
276 |
} |
49 |
|
|
|
50 |
|
|
#endif // _Tag_hpp_ |