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/>.
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_
,
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();
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() );
47 digest
.write( pAttr_
->getName().c_str(), pAttr_
->getName().size() );
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"
54 "\t\ttypedef " << typestring
.str() <<
57 bool bGenerateGetSet
= pAttr_
->testFlag( "Scriptable", true );
58 bool bMutable
= pAttr_
->testFlag( "Mutable", true );
59 bool bReadOnly
= pAttr_
->testFlag( "ReadOnly", false );
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";
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";
84 Out_
<< "\t\tstatic type C::* MemberPointer() { return &C::m_" << pAttr_
->getName() << "; }\n";
88 Out_
<< "\t\tstatic getter_type Getter() { return &C::get" << pAttr_
->getName() << "; }\n";
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";
100 Out_
<< "\t\tstatic accessor_type Accessor() { return &C::" << pAttr_
->getName() << "; }\n"
101 "\t\tstatic getter_type Getter() { return &C::" << pAttr_
->getName() << "; }\n";