8 using namespace awful::awic
;
13 void GenerateModuleHeaderName( std::ostream
& Out_
, const idlast::Namespace
* pNamespace_
)
15 vector
< string
> NSNames
;
16 const idlast::Namespace
* pCurrentNS
= pNamespace_
;
17 while( pCurrentNS
->getParent() )
19 NSNames
.push_back( pCurrentNS
->getName() );
20 pCurrentNS
= pCurrentNS
->getParent();
24 vector
< string
>::const_reverse_iterator it
;
25 for( it
= NSNames
.rbegin(); it
!= NSNames
.rend(); ++it
)
29 if( ( it
- NSNames
.rbegin() + vector
< string
>::size_type( 1 ) ) < NSNames
.size() )
37 void awful::awic::GenerateModuleFiles( const idlast::Namespace
* pNamespace_
)
39 // Build an array of namespace names, from the root namespace to the one we're interested in.
41 std::stringstream filename
;
42 GenerateModuleHeaderName( filename
, pNamespace_
);
43 ofstream
file( filename
.str().c_str() );
45 vector
< string
> NSNames
;
46 const idlast::Namespace
* pCurrentNS
= pNamespace_
;
47 while( pCurrentNS
->getParent() )
49 NSNames
.push_back( pCurrentNS
->getName() );
50 pCurrentNS
= pCurrentNS
->getParent();
54 vector
< string
>::const_reverse_iterator it
;
55 for( it
= NSNames
.rbegin(); it
!= NSNames
.rend(); ++it
)
56 defname
<< '_' << *it
;
59 "// Automatically generated by AWIC (AWful IDL Compiler).\n"
61 "#ifndef MODULE" << defname
.str() << "_H_\n"
62 "#define MODULE" << defname
.str() << "_H_\n\n"
63 "#include \"core/core.h\"\n";
65 const idlast::NamespaceDependencySet
& deps
= pNamespace_
->getDependencies();
66 idlast::NamespaceDependencySet::const_iterator depit
;
67 for( depit
= deps
.begin(); depit
!= deps
.end(); ++depit
)
69 file
<< "#include \"";
70 GenerateModuleHeaderName( file
, *depit
);
76 for( it
= NSNames
.rbegin(); it
!= NSNames
.rend(); ++it
)
78 file
<< "namespace " << *it
;
80 if( ( it
- NSNames
.rbegin() + vector
< string
>::size_type( 1 ) ) < NSNames
.size() )
86 "\tstruct awful_tag {};\n";
88 for( unsigned int i
= 0; i
< NSNames
.size(); ++i
)
93 const idlast::Dictionary
< idlast::Class
>& Classes
= pNamespace_
->getClasses();
94 idlast::Dictionary
< idlast::Class
>::const_iterator clit
;
96 for( clit
= Classes
.begin(); clit
!= Classes
.end(); ++clit
)
98 file
<< "#include \"" << clit
->second
->getName() << ".h\"\n";
99 file
<< "#include \"traits_" << clit
->second
->getName() << ".h\"\n";
102 const idlast::Dictionary
< idlast::Class
>& Structs
= pNamespace_
->getStructs();
103 idlast::Dictionary
< idlast::Class
>::const_iterator stit
;
104 for( stit
= Structs
.begin(); stit
!= Structs
.end(); ++stit
)
106 file
<< "#include \"" << stit
->second
->getName() << ".h\"\n";
107 file
<< "#include \"traits_" << stit
->second
->getName() << ".h\"\n";
113 "\ttemplate<> struct module_traits< ";
115 stringstream FullNSName
;
116 for( it
= NSNames
.rbegin(); it
!= NSNames
.rend(); ++it
)
120 if( ( it
- NSNames
.rbegin() + vector
< string
>::size_type( 1 ) ) < NSNames
.size() )
125 digest
.write( FullNSName
.str().c_str(), FullNSName
.str().size() );
127 file
<< FullNSName
.str() << "::awful_tag >\n"
129 "\t\tstatic uint32_t Digest() { return 0x" << std::hex
<< digest
.result() << "; }\n"
130 "\t\tstatic const char* Name() { return \"" << NSNames
[0] << "\"; }\n"
131 "\t\tstatic const char* FullName() { return \"" << FullNSName
.str() << "\"; }\n\n"
132 "\t\ttemplate< class V > static void VisitQualifiedName( V& Visitor_ )\n"
135 for( it
= NSNames
.rbegin(); it
!= NSNames
.rend(); ++it
)
136 file
<< "\t\t\tVisitor_.QualifiedNameComponent( \"" << *it
<< "\" );\n";
140 "\t\ttemplate< class V > static void VisitClasses( V& Visitor_ )\n"
143 for( clit
= Classes
.begin(); clit
!= Classes
.end(); ++clit
)
145 file
<< "\t\t\tVisitor_.template Class< "
146 << FullNSName
.str() << "::" << clit
->second
->getName() << " >();\n";
149 for( stit
= Structs
.begin(); stit
!= Structs
.end(); ++stit
)
151 file
<< "\t\t\tVisitor_.template Struct< "
152 << FullNSName
.str() << "::" << stit
->second
->getName() << " >();\n";