Parser WIP.
[fail.git] / src / idl / failit / attribute.cpp
blobeea9bd2bd6a623f3f0eb84f49e4596794a9e0e3a
1 /*
2 Fail game engine
3 Copyright 2007 Antoine Chavasse <a.chavasse@gmail.com>
5 This file is part of Fail.
7 Fail is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3
9 as published by the Free Software Foundation.
11 Fail is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <ostream>
20 #include <sstream>
21 #include "failit.h"
23 using namespace fail::failit;
25 void fail::failit::GenerateAttrTraits( ostream& Out_,
26 shared_ptr< const idlast::Class > pClass_,
27 shared_ptr< const idlast::Attribute > pAttr_,
28 bool bStruct_ )
30 string FullClassName( pClass_->getName() );
31 shared_ptr< const idlast::Namespace > pCurrentNS = pClass_->getNamespace();
32 while( pCurrentNS->getParent() )
34 FullClassName = pCurrentNS->getName() + "::" + FullClassName;
35 pCurrentNS = pCurrentNS->getParent();
38 Out_ << '\n';
39 stringstream tagstring;
40 tagstring << "class_traits< " << FullClassName << " >::attribute_tags::" << pAttr_->getName();
41 OutputFlags( Out_, pAttr_->getFlags(), tagstring.str() );
43 stringstream typestring;
44 PrintType( typestring, pAttr_->getType() );
46 crc32 digest;
47 digest.write( pAttr_->getName().c_str(), pAttr_->getName().size() );
48 digest.write( ' ' );
49 digest.write( typestring.str().c_str(), typestring.str().size() );
51 Out_ << "\ttemplate< class C > struct attribute_traits< C,\n"
52 "\t\t" << tagstring.str() << " >\n"
53 "\t{\n"
54 "\t\ttypedef " << typestring.str() <<
55 " type;\n";
57 bool bGenerateGetSet = pAttr_->testFlag( "Scriptable", true );
58 bool bMutable = pAttr_->testFlag( "Mutable", true );
59 bool bReadOnly = pAttr_->testFlag( "ReadOnly", false );
61 if( bStruct_ )
63 Out_ << "\t\ttypedef type& ( C::* accessor_type )();\n"
64 "\t\ttypedef const type& ( C::* getter_type )() const;\n\n";
66 else if( bGenerateGetSet )
68 Out_ << "\t\ttypedef const type& ( C::* getter_type )() const;\n";
70 if( !bReadOnly )
72 if( bMutable )
73 Out_ << "\t\ttypedef type& ( C::* getter_mutable_type )();\n";
74 Out_ << "\t\ttypedef void ( C::* setter_type )( const type& );\n\n";
79 Out_ << "\t\tstatic uint32_t Digest() { return 0x" << std::hex << digest.result() << "; }\n"
80 "\t\tstatic const char* Name() { return \"" << pAttr_->getName() << "\"; }\n\n";
82 if( !bStruct_ )
84 Out_ << "\t\tstatic type C::* MemberPointer() { return &C::m_" << pAttr_->getName() << "; }\n";
86 if( bGenerateGetSet )
88 Out_ << "\t\tstatic getter_type Getter() { return &C::get" << pAttr_->getName() << "; }\n";
90 if( !bReadOnly )
92 if( bMutable )
93 Out_ << "\t\tstatic getter_mutable_type GetterMutable() { return &C::get" << pAttr_->getName() << "; }\n";
94 Out_ << "\t\tstatic setter_type Setter() { return &C::set" << pAttr_->getName() << "; }\n";
98 else
100 Out_ << "\t\tstatic accessor_type Accessor() { return &C::" << pAttr_->getName() << "; }\n"
101 "\t\tstatic getter_type Getter() { return &C::" << pAttr_->getName() << "; }\n";
104 Out_ << "\t};\n";