Bidjic set to set
Description
Generates multiple output files from multiple input models, using fileset and templateset.
+---+ +---+
| | +---> | |
| | | |
+---+ +---+
+---+ +---+
| | +---> | |
| | | |
+---+ +---+
Bidjic task parameters
Attribute | Description | Value | Required |
---|---|---|---|
todir | output dir | yes | |
overwrite | overwrite output file | true by default | no |
Element | Description | Value | Required |
---|---|---|---|
templateset | template set | yes | |
fileset | file set | if no filelist | |
filelist | file list | if no fileset |
Example
Generates cpp - c++ classes from Model driven architecture abstraction: bidjim entities.
download set2set.tgz sample.
ant file : build.xml
<target name="cpp" description="generate cpp files">
<bidjic todir="gen" overwrite="true">
<fileset dir="MyPackage">
<include name="**/*.bidjim"/>
</fileset>
<templateset dir="templates">
<include name="*.ftl"/>
</templateset>
</bidjic>
</target>
Note
Output file names are processed from template names:
- Model.cpp.ftl + MyPackage/MyModule/Foo.bidjim => Foo.cpp
- Module.cpp.ftl + MyPackage/MyModule/Foo.bidjim => MyModule.cpp
template: Model.h.ftl
[#assign entity = bidji.entity]
#ifndef _${PACKAGE}_${MODULE}_${MODEL}_H_
#define _${PACKAGE}_${MODULE}_${MODEL}_H_
namespace ${Package} {
namespace ${Module} {
class ${Model}
{
private:
[#foreach property in entity.property]
${property.@type} _${property.@name};
[/#foreach]
public:
${Model}();
virtual ~${Model}();
public:
[#foreach property in entity.property]
void set${property.@name?cap_first}(const ${property.@type} & ${property.@name});
const ${property.@type} & get${property.@name?cap_first}() const;
[/#foreach]
}; // class ${Model}
[#foreach property in entity.property]
inline const ${property.@type} &
${Model}::get${property.@name?cap_first}() const
{
return _${property.@name};
}
[/#foreach]
} } // namespace ${Package}::${Module}
#endif // #ifndef _${PACKAGE}_${MODULE}_${MODEL}_H_
template: Model.cpp.ftl
[#assign entity = bidji.entity]
#include "${Model}.h"
using namespace ${Package}::${Module};
${Model}::${Model}()
[#foreach property in entity.property]
[#if property.@type == 'int']
, _${property.@name}(-1)
[#elseif property.@type == 'string']
, _${property.@name}("")
[#else]
, _${property.@name}()
[/#if]
[/#foreach]
{
}
${Model}::~${Model}()
{
}
[#foreach property in entity.property]
void
${Model}::set${property.@name?cap_first}(const ${property.@type} & ${property.@name})
{
this->_${property.@name} = ${property.@name};
}
[/#foreach]
models: MyPackage/MyModule/(Foo|Baz).bidjim
<?xml version="1.0"?>
<bidji>
<entity name="Foo">
<property name="id" type="int" />
<property name="name" type="string" />
</entity>
</bidji>
result: Foo.h
#ifndef _MYPACKAGE_MYMODULE_FOO_H_
#define _MYPACKAGE_MYMODULE_FOO_H_
namespace MyPackage {
namespace MyModule {
class Foo
{
private:
int _id;
string _name;
public:
Foo();
virtual ~Foo();
public:
void setId(const int & id);
const int & getId() const;
void setName(const string & name);
const string & getName() const;
}; // class Foo
inline const int &
Foo::getId() const
{
return _id;
}
inline const string &
Foo::getName() const
{
return _name;
}
} } // namespace MyPackage::MyModule
#endif // #ifndef _MYPACKAGE_MYMODULE_FOO_H_
result: Foo.cpp
#include "Foo.h"
using namespace MyPackage::MyModule;
Foo::Foo()
, _id(-1)
, _name("")
{
}
Foo::~Foo()
{
}
void
Foo::setId(const int & id)
{
this->_id = id;
}
void
Foo::setName(const string & name)
{
this->_name = name;
}