Parse module type.

svn path=/branches/xmlbuildsystem/; revision=12839
This commit is contained in:
Casper Hornstrup 2005-01-05 21:29:54 +00:00
parent 1568981925
commit 91d97cbc91
6 changed files with 45 additions and 11 deletions

View file

@ -63,5 +63,13 @@ RequiredAttributeNotFoundException::RequiredAttributeNotFoundException(const std
attributeName.c_str (),
elementName.c_str ())
{
}
InvalidAttributeValueException::InvalidAttributeValueException(const std::string& name,
const std::string& value)
: InvalidBuildFileException ( "Attribute '%s' has an invalid value '%s'.",
name.c_str (),
value.c_str ())
{
}

View file

@ -48,4 +48,12 @@ public:
const std::string& elementName);
};
class InvalidAttributeValueException : public InvalidBuildFileException
{
public:
InvalidAttributeValueException(const std::string& name,
const std::string& value);
};
#endif /* __EXCEPTION_H */

View file

@ -14,35 +14,43 @@ Module::Module ( const XMLElement& moduleNode,
name(moduleName),
path(modulePath)
{
type = GetModuleType ( *moduleNode.GetAttribute ( "type", true ) );
}
Module::~Module()
Module::~Module ()
{
for ( size_t i = 0; i < files.size(); i++ )
delete files[i];
}
void
Module::ProcessXML ( const XMLElement& e, const string& path )
void Module::ProcessXML ( const XMLElement& e,
const string& path )
{
string subpath ( path );
if ( e.name == "file" && e.value.size() )
if ( e.name == "file" && e.value.size () )
{
files.push_back ( new File(path + "/" + e.value) );
files.push_back ( new File ( path + "/" + e.value ) );
}
else if ( e.name == "directory" )
{
// this code is duplicated between Project::ProcessXML() and Module::ProcessXML() :(
const XMLAttribute* att = e.GetAttribute ( "name", true );
if ( !att )
return;
subpath = path + "/" + att->value;
}
for ( size_t i = 0; i < e.subElements.size(); i++ )
for ( size_t i = 0; i < e.subElements.size (); i++ )
ProcessXML ( *e.subElements[i], subpath );
}
File::File ( const std::string& _name )
ModuleType Module::GetModuleType ( const XMLAttribute& attribute )
{
if ( attribute.value == "buildtool" )
return BuildTool;
if ( attribute.value == "kernelmodedll" )
return KernelModeDLL;
throw InvalidAttributeValueException ( attribute.name,
attribute.value );
}
File::File ( const string& _name )
: name(_name)
{
}

View file

@ -30,6 +30,12 @@ private:
};
enum ModuleType
{
BuildTool,
KernelModeDLL
};
class Module
{
public:
@ -37,10 +43,12 @@ public:
std::string name;
std::string path;
std::vector<File*> files;
ModuleType type;
Module ( const XMLElement& moduleNode,
const std::string& moduleName,
const std::string& modulePath );
ModuleType GetModuleType (const XMLAttribute& attribute );
~Module();

View file

@ -6,7 +6,7 @@
</module>
</directory>
<directory name="dir2">
<module name="module2" type="buildtool">
<module name="module2" type="kernelmodedll">
<file>file3.c</file>
<file>file4.c</file>
</module>

View file

@ -9,11 +9,13 @@ void ModuleTest::Run()
ARE_EQUAL(2, project.modules.size());
Module& module1 = *project.modules[0];
IS_TRUE(module1.type == BuildTool);
ARE_EQUAL(2, module1.files.size());
ARE_EQUAL("./dir1/file1.c", module1.files[0]->name);
ARE_EQUAL("./dir1/file2.c", module1.files[1]->name);
Module& module2 = *project.modules[1];
IS_TRUE(module2.type == KernelModeDLL);
ARE_EQUAL(2, module2.files.size());
ARE_EQUAL("./dir2/file3.c", module2.files[0]->name);
ARE_EQUAL("./dir2/file4.c", module2.files[1]->name);