Reshuffling directories to separate include and sources, part one.
[fail.git] / include / core / awic / attribute.cpp
blobf98e16b8082b3f59524fefb6336ff5679b3d6620
1 #include <ostream>
2 #include <sstream>
3 #include "core/idlast/namespace.h"
4 #include "attribute.h"
5 #include "type.h"
6 #include "flags.h"
7 #include "crc32.h"
9 using namespace awful::awic;
10 using namespace std;
12 void awful::awic::GenerateAttrTraits( std::ostream& Out_,
13 const idlast::Class* pClass_,
14 const idlast::Attribute* pAttr_,
15 bool bStruct_ )
17 string FullClassName( pClass_->getName() );
18 const idlast::Namespace* pCurrentNS = pClass_->getNamespace();
19 while( pCurrentNS->getParent() )
21 FullClassName = pCurrentNS->getName() + "::" + FullClassName;
22 pCurrentNS = pCurrentNS->getParent();
25 Out_ << '\n';
26 std::stringstream tagstring;
27 tagstring << "class_traits< " << FullClassName << " >::attribute_tags::" << pAttr_->getName();
28 OutputFlags( Out_, pAttr_->getFlags(), tagstring.str() );
30 std::stringstream typestring;
31 PrintType( typestring, pAttr_->getType() );
33 crc32 digest;
34 digest.write( pAttr_->getName().c_str(), pAttr_->getName().size() );
35 digest.write( ' ' );
36 digest.write( typestring.str().c_str(), typestring.str().size() );
38 Out_ << "\ttemplate< class C > struct attribute_traits< C,\n"
39 "\t\t" << tagstring.str() << " >\n"
40 "\t{\n"
41 "\t\ttypedef " << typestring.str() <<
42 " type;\n"
43 "\t\ttypedef ";
45 PrintTypeCategory( Out_, pAttr_->getType() );
47 Out_ << " category;\n";
49 bool bGenerateGetSet = pAttr_->testFlag( "Scriptable", true );
50 bool bMutable = pAttr_->testFlag( "Mutable", true );
51 bool bReadOnly = pAttr_->testFlag( "ReadOnly", false );
54 if( bStruct_ )
56 Out_ << "\t\ttypedef type& ( C::* accessor_type )();\n"
57 "\t\ttypedef const type& ( C::* getter_type )() const;\n\n";
59 else if( bGenerateGetSet )
61 Out_ << "\t\ttypedef const type& ( C::* getter_type )() const;\n";
63 if( !bReadOnly )
65 if( bMutable )
66 Out_ << "\t\ttypedef type& ( C::* getter_mutable_type )();\n";
67 Out_ << "\t\ttypedef void ( C::* setter_type )( const type& );\n\n";
72 Out_ << "\t\tstatic uint32_t Digest() { return 0x" << std::hex << digest.result() << "; }\n"
73 "\t\tstatic const char* Name() { return \"" << pAttr_->getName() << "\"; }\n\n";
75 if( !bStruct_ )
77 Out_ << "\t\tstatic type C::* MemberPointer() { return &C::m_" << pAttr_->getName() << "; }\n";
79 if( bGenerateGetSet )
81 Out_ << "\t\tstatic getter_type Getter() { return &C::get" << pAttr_->getName() << "; }\n";
83 if( !bReadOnly )
85 if( bMutable )
86 Out_ << "\t\tstatic getter_mutable_type GetterMutable() { return &C::get" << pAttr_->getName() << "; }\n";
87 Out_ << "\t\tstatic setter_type Setter() { return &C::set" << pAttr_->getName() << "; }\n";
91 else
93 Out_ << "\t\tstatic accessor_type Accessor() { return &C::" << pAttr_->getName() << "; }\n"
94 "\t\tstatic getter_type Getter() { return &C::" << pAttr_->getName() << "; }\n";
97 Out_ << "\t};\n";