Go to the documentation of this file.00001 #ifndef __TEMPLATE_ENGINE_CPP__
00002 #define __TEMPLATE_ENGINE_CPP__
00003
00004 #include <utilities/file_utilities.h>
00005 #include <utilities/template_engine.h>
00006 #include <utilities/testing_utilities.h>
00007
00008 namespace nitro
00009 {
00010 void TemplateEngine::LoadTemplateFromFile( const char * FilePath )
00011 {
00012 try
00013 {
00014 nitro::File::LoadBinDataFromFile( TemplateData , FilePath );
00015 }
00016 catch( nitro::exception e )
00017 {
00018 throw( nitro::exception( std::string( "TemplateEngine::LoadTemplateFromFile( const char * FilePath )::" ) + e.what() , e.code() ) );
00019 }
00020 catch( ... )
00021 {
00022 throw( nitro::exception( std::string( "TemplateEngine::LoadTemplateFromFile( const char * FilePath )::An error occured" ) , 0 ) );
00023 }
00024 }
00025
00026 void TemplateEngine::SetVariable( const char * VariableName , const char * VariableValue )
00027 {
00028 try
00029 {
00030 for( int OccurancePos( 0 ) ; ( OccurancePos = nitro::BinaryData::GetFirstOccurance( TemplateData , ( std::string( "{" ) + VariableName + std::string( "}" ) ).c_str() , strlen( VariableName ) ) ) != -1 ; )
00031 {
00032 nitro::BinaryData::ReplaceBuffer( TemplateData , OccurancePos , strlen( VariableName ) + 2 , VariableValue , strlen( VariableValue ) );
00033 }
00034 }
00035 catch( nitro::exception e )
00036 {
00037 throw( nitro::exception( std::string( "TemplateEngine::SetVariable( const char * VariableName , const char * VariableValue )::" ) + e.what() , e.code() ) );
00038 }
00039 catch( ... )
00040 {
00041 throw( nitro::exception( std::string( "TemplateEngine::SetVariable( const char * VariableName , const char * VariableValue )::An error occured" ) , 0 ) );
00042 }
00043 }
00044
00045 const nitro::BinaryData & TemplateEngine::GetTemplate( void ) const
00046 {
00047 try
00048 {
00049 return( TemplateData );
00050 }
00051 catch( nitro::exception e )
00052 {
00053 throw( nitro::exception( std::string( "TemplateEngine::TemplateEngine::GetTemplate( void )::" ) + e.what() , e.code() ) );
00054 }
00055 catch( ... )
00056 {
00057 throw( nitro::exception( std::string( "TemplateEngine::TemplateEngine::GetTemplate( void )::An error occured" ) , 0 ) );
00058 }
00059 }
00060
00061 void TemplateEngine::LoadTemplateFromFile( const std::string & FilePath )
00062 {
00063 try
00064 {
00065 LoadTemplateFromFile( FilePath.c_str() );
00066 }
00067 catch( nitro::exception e )
00068 {
00069 throw( nitro::exception( std::string( "TemplateEngine::LoadTemplateFromFile( const std::string & FilePath )::" ) + e.what() , e.code() ) );
00070 }
00071 catch( ... )
00072 {
00073 throw( nitro::exception( std::string( "TemplateEngine::LoadTemplateFromFile( const std::string & FilePath )::An error occured" ) , 0 ) );
00074 }
00075 }
00076
00077 void TemplateEngine::SetVariable( const std::string & VariableName , const std::string & VariableValue )
00078 {
00079 try
00080 {
00081 SetVariable( VariableName.c_str() , VariableValue.c_str() );
00082 }
00083 catch( nitro::exception e )
00084 {
00085 throw( nitro::exception( std::string( "TemplateEngine::SetVariable( const std::string & VariableName , const std::string & VariableValue )::" ) + e.what() , e.code() ) );
00086 }
00087 catch( ... )
00088 {
00089 throw( nitro::exception( std::string( "TemplateEngine::SetVariable( const std::string & VariableName , const std::string & VariableValue )::An error occured" ) , 0 ) );
00090 }
00091 }
00092
00093 TemplateEngine::~TemplateEngine( void )
00094 {
00095 try
00096 {
00097 }
00098 catch( ... )
00099 {
00100 }
00101 }
00102
00103 BEGIN_TESTING_SECTION()
00104
00105 ENABLE_CLASS_TESTING( TemplateEngine )
00106
00107 CLASS_MEMBER_FUNCTION_TESTING_1( TemplateEngine , aliasLoadTemplateFromFile , tstLoadTemplateFromFile , const char * , void , NO_RET )
00108 CLASS_MEMBER_FUNCTION_TESTING_2( TemplateEngine , aliasSetVariable , tstSetVariable , const char * , const char * , void , NO_RET )
00109
00110 #ifdef ENABLE_AUTOTESTING
00111 NITRO_EXPORTING const char * tstGetTemplate( const char * ObjectName )
00112 {
00113 return( GET_OBJECT_PTR( TemplateEngine , ObjectName )->GetTemplate().GetBuffer() );
00114 }
00115 #endif
00116
00117
00118
00119 END_TESTING_SECTION()
00120 }
00121
00122 #endif