comparison dbus-d/dsrc/org/freedesktop/dbus/DBus.d @ 5:7c2c75740370

code generation for signals
author Frank Benoit <benoit@tionex.de>
date Sun, 21 Oct 2007 19:22:41 +0200
parents a5576806d36d
children 963d271f7c25
comparison
equal deleted inserted replaced
4:427c0332a111 5:7c2c75740370
1103 getVariantAsKnownType!( DBusVariant[ DBusVariant ] )( null ); 1103 getVariantAsKnownType!( DBusVariant[ DBusVariant ] )( null );
1104 getVariantAsKnownType!( Struct!( int[], long, char[], Struct!( bool ) ) )( null ); 1104 getVariantAsKnownType!( Struct!( int[], long, char[], Struct!( bool ) ) )( null );
1105 } 1105 }
1106 1106
1107 1107
1108 /**
1109 * this function shall be used like so:
1110 * ---
1111 * mixin( createJavaImplementation( "MyClass", ["I1", "I2" ] ));
1112 * ---
1113 * This creates a simple standard implementation by generating code in this form:
1114 * ---
1115 * class MyClass : I1, I2 {
1116 * mixin I1.JImpl!();
1117 * mixin I2.JImpl!();
1118 * }
1119 * ---
1120 * The given array with interfaces must not be zero length
1121 */
1122 char[] createJavaImplementation( char[] className, char[][] interfaces ){
1123 assert( interfaces.length > 0 );
1124 char[] res = "class "~className~ " ";
1125 bool first = true;
1126 foreach( intf; interfaces ){
1127 res ~= first ? ": " : ", ";
1128 first = false;
1129 res ~= intf;
1130 }
1131 res ~= " {\n";
1132 foreach( intf; interfaces ){
1133 res ~= " mixin "~intf~"._StdJavaImpl!();\n";
1134 }
1135 res ~= "}\n";
1136 return res;
1137 }
1138
1139 char[] ctfeReplace( char[] text, char s, char r ){
1140 char[] res;
1141 foreach( c; text ){
1142 res ~= ( c == s ) ? r : c;
1143 }
1144 return res;
1145 }
1146 char[] createDImplementation( char[] className, char[][] interfaces ){
1147 assert( interfaces.length > 0 );
1148 char[] res = "abstract class "~className~ " : DBusObjectImpl ";
1149 foreach( intf; interfaces ){
1150 res ~= ", ";
1151 res ~= intf;
1152 }
1153 res ~= " {\n";
1154 foreach( intf; interfaces ){
1155 res ~= " mixin "~intf~"._StdDImpl!() _StdDImpl_"~ctfeReplace( intf, '.', '_' )~";\n";
1156 }
1157 res ~= " protected this(){\n";
1158 foreach( intf; interfaces ){
1159 res ~= " _StdDImpl_"~ ctfeReplace( intf, '.', '_' ) ~"._init();\n";
1160 }
1161 res ~= " }\n";
1162 res ~= "}\n";
1163 return res;
1164 }
1165
1166
1167