2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 extern std::string working_directory
;
30 InitWorkingDirectory();
42 XMLException ( const std::string
& location
, const char* format
, ... );
43 const std::string
& operator *() { return _e
; }
47 void SetExceptionV ( const std::string
& location
, const char* format
, va_list args
);
48 void SetException ( const std::string
& location
, const char* format
, ... );
54 class XMLSyntaxErrorException
: public XMLException
57 XMLSyntaxErrorException (
58 const std::string
& location
,
59 const char* format
, ... )
62 va_start ( args
, format
);
63 SetExceptionV ( location
, format
, args
);
68 class XMLRequiredAttributeNotFoundException
: public XMLException
71 XMLRequiredAttributeNotFoundException (
72 const std::string
& location
,
73 const std::string
& attributeName
,
74 const std::string
& elementName
)
76 SetException ( location
, "Required attribute '%s' not found in element '%s'",
77 attributeName
.c_str(),
78 elementName
.c_str() );
82 class XMLInvalidBuildFileException
: public XMLException
85 XMLInvalidBuildFileException (
86 const std::string
& location
,
91 va_start ( args
, format
);
92 SetExceptionV ( location
, format
, args
);
97 class XMLFileNotFoundException
: public XMLException
100 XMLFileNotFoundException (
101 const std::string
& location
,
102 const std::string
& filename
)
104 SetException ( location
, "Can't open file '%s'", filename
.c_str() );
110 std::vector
<std::string
> path
;
112 Path(); // initializes path to getcwd();
113 Path ( const Path
& cwd
, const std::string
& filename
);
114 std::string
Fixup ( const std::string
& filename
, bool include_filename
) const;
116 std::string
RelativeFromWorkingDirectory ();
117 static std::string
RelativeFromWorkingDirectory ( const std::string
& path
);
118 static std::string
RelativeFromDirectory ( const std::string
& path
, const std::string
& base_directory
);
121 std::vector
<std::string
>& out
,
122 const std::string
& path
,
131 std::string topIncludeFilename
;
137 const std::string topIncludeFilename_
)
140 topIncludeFilename ( topIncludeFilename_
)
145 class XMLIncludes
: public std::vector
<XMLInclude
*>
153 friend class XMLElement
;
157 bool open(const std::string
& filename
);
161 bool get_token ( std::string
& token
);
162 bool get_token ( std::string
& token
, std::string
& location
);
163 const std::string
& filename() { return _filename
; }
164 std::string
Location() const;
167 std::string _buf
, _filename
;
169 const char *_p
, *_end
;
180 XMLAttribute ( const std::string
& name_
, const std::string
& value_
);
181 XMLAttribute ( const XMLAttribute
& );
182 XMLAttribute
& operator = ( const XMLAttribute
& );
190 std::string location
;
192 std::vector
<XMLAttribute
*> attributes
;
193 XMLElement
* parentElement
;
194 std::vector
<XMLElement
*> subElements
;
199 const std::string
& location
);
204 const std::string
& token
,
207 void AddSubElement ( XMLElement
* e
);
209 XMLAttribute
* GetAttribute (
210 const std::string
& attribute
,
213 const XMLAttribute
* GetAttribute (
214 const std::string
& attribute
,
215 bool required
) const;
218 const std::string
& type
,
219 int prev
= -1 ) const;
222 const std::string
& type
,
223 std::vector
<XMLElement
*>& v
);
226 const std::string
& type
,
227 std::vector
<const XMLElement
*>& v
) const;
232 const std::string
& filename
,
234 XMLIncludes
& includes
);
237 XMLLoadFile ( const std::string
& filename
);