9 Tag(const std::string
& i_short_name
,
10 const std::string
& i_name
,
11 const std::string
& i_long_name
)
12 : short_name(i_short_name
), name(i_name
),
13 long_name(i_long_name
)
25 virtual std::istream
& Read(std::istream
& is
)
29 virtual std::ostream
& Write(std::ostream
& os
)
34 virtual void ClearImpl() {}
36 std::string short_name
;
38 std::string long_name
;
49 virtual ~TagParser () {}
53 // erases all tag's data
55 for (std::vector
<Tag
*>::size_type i
= 0;
60 bool Parse(const std::string
& file
)
65 std::ifstream
src_file(file
.c_str());
68 std::cerr
<< file
<< ": Can not open file!" << std::endl
;
73 std::string tag
, value
;
74 for (int linenr
= 0; src_file
; ++linenr
) {
75 std::getline(src_file
, line
);
80 // skip comments (maybe we also need to compress
81 // whitespaces? -ReneR
82 if (line
[0] == '#' || line
[0] == ' ')
85 if (line
.size() < 3) {
87 std::cerr
<< file
<< ":"
88 << linenr
<< ": only garbage in this line." << std::endl
89 << " '" << line
<< "'" << std::endl
;
92 std::string::size_type idx
= line
.find(' ');
93 if (idx
== std::string::npos
)
96 if (line
[0] != '[' || line
[idx
- 1] != ']') {
98 std::cerr
<< file
<< ":" << linenr
<< ": this line contains no tag." << std::endl
99 << " '" << line
<< "'" << std::endl
;
104 tag
.append(line
, 1, idx
- 2);
106 value
.append(line
, idx
, std::string::npos
);
108 // search thru "registered" tags
109 bool tag_found
= false;
110 for (std::vector
<Tag
*>::size_type i
= 0;
111 i
< tags
.size(); ++i
) {
112 if (tag
== tags
[i
]->short_name
||
113 tag
== tags
[i
]->long_name
||
114 tag
== tags
[i
]->name
)
116 tags
[i
]->value
.append (value
+ '\n');
117 //std::cerr << line << std::endl;
118 //std::cerr << tag << ": " << value << std::endl;
126 std::cerr
<< file
<< ":" << linenr
<< ": Unknown tag '" << tag
<< "'" << std::endl
;
132 // derived class has to fill this vector
133 std::vector
<Tag
*> tags
;