[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19295] branches/blender2.5/blender/source /blender/makesrna: RNA:

Brecht Van Lommel brecht at blender.org
Sun Mar 15 00:17:55 CET 2009


Revision: 19295
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19295
Author:   blendix
Date:     2009-03-15 00:17:55 +0100 (Sun, 15 Mar 2009)

Log Message:
-----------
RNA:

- Added an autogenerated C++ API, basically a simple layer over the C
  API, but with the advantage that it fits the object oriented RNA
  model better. Read-only still like the C API.
- Had to rename "protected" property in Action Group because it is
  a C++ keyword, called it "locked" since that seems more consistent
  anyway?
- It's not used anywhere, so here's some example code I used to test it,
  to get an idea of how it would be used:

http://pasteall.org/4582/cpp

- Also, ID names are now editable.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
    branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_ID.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_action.c

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2009-03-14 20:42:58 UTC (rev 19294)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2009-03-14 23:17:55 UTC (rev 19295)
@@ -27,6 +27,10 @@
 
 #include "RNA_types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct bContext;
 struct ID;
 struct Main;
@@ -303,6 +307,7 @@
 PropertyRNA *RNA_struct_iterator_property(PointerRNA *ptr);
 
 int RNA_struct_is_ID(PointerRNA *ptr);
+int RNA_struct_is_a(PointerRNA *ptr, StructRNA *srna);
 
 PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier);
 const struct ListBase *RNA_struct_defined_properties(StructRNA *srna);
@@ -476,7 +481,9 @@
 /* python compatible string representation of this property, (must be freed!) */
 char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* RNA_ACCESS */
 
-
-

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_define.h	2009-03-14 20:42:58 UTC (rev 19294)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_define.h	2009-03-14 23:17:55 UTC (rev 19295)
@@ -33,6 +33,10 @@
 #include "DNA_listBase.h"
 #include "RNA_types.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Blender RNA */
 
 BlenderRNA *RNA_create(void);
@@ -146,6 +150,9 @@
 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set);
 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* RNA_DEFINE_H */
 
-

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_types.h	2009-03-14 20:42:58 UTC (rev 19294)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_types.h	2009-03-14 23:17:55 UTC (rev 19295)
@@ -25,6 +25,10 @@
 #ifndef RNA_TYPES
 #define RNA_TYPES
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct PropertyRNA;
 struct StructRNA;
 struct BlenderRNA;
@@ -148,6 +152,10 @@
 
 typedef struct BlenderRNA BlenderRNA;
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* RNA_TYPES */
 
 

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c	2009-03-14 20:42:58 UTC (rev 19294)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c	2009-03-14 23:17:55 UTC (rev 19295)
@@ -861,6 +861,154 @@
 	fprintf(f, "\n");
 }
 
+static void rna_def_property_funcs_header_cpp(FILE *f, PropertyDefRNA *dp)
+{
+	PropertyRNA *prop;
+	StructRNA *srna;
+
+	srna= dp->srna;
+	prop= dp->prop;
+
+	if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
+		return;
+	
+	if(prop->name && prop->description && strcmp(prop->description, "") != 0)
+		fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
+	else if(prop->name)
+		fprintf(f, "\t/* %s */\n", prop->name);
+	else
+		fprintf(f, "\t/* */\n");
+
+	switch(prop->type) {
+		case PROP_BOOLEAN: {
+			if(!prop->arraylength)
+				fprintf(f, "\tbool %s(void);", prop->identifier);
+			else
+				fprintf(f, "\tArray<int, %d> %s(void);", prop->arraylength, prop->identifier);
+			break;
+		}
+		case PROP_INT: {
+			if(!prop->arraylength)
+				fprintf(f, "\tint %s(void);", prop->identifier);
+			else
+				fprintf(f, "\tArray<int, %d> %s(void);", prop->arraylength, prop->identifier);
+			break;
+		}
+		case PROP_FLOAT: {
+			if(!prop->arraylength)
+				fprintf(f, "\tfloat %s(void);", prop->identifier);
+			else
+				fprintf(f, "\tArray<float, %d> %s(void);", prop->arraylength, prop->identifier);
+			break;
+		}
+		case PROP_ENUM: {
+			EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
+			int i;
+
+			if(eprop->item) {
+				fprintf(f, "\tenum %s_enum {\n", prop->identifier);
+
+				for(i=0; i<eprop->totitem; i++)
+					fprintf(f, "\t\t%s_%s = %d,\n", prop->identifier, eprop->item[i].identifier, eprop->item[i].value);
+
+				fprintf(f, "\t};\n");
+			}
+
+			fprintf(f, "\t%s_enum %s(void);", prop->identifier, prop->identifier);
+			break;
+		}
+		case PROP_STRING: {
+			fprintf(f, "\tstd::string %s(void);", prop->identifier);
+			break;
+		}
+		case PROP_POINTER: {
+			PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
+
+			if(pprop->structtype)
+				fprintf(f, "\t%s %s(void);", (char*)pprop->structtype, prop->identifier);
+			else
+				fprintf(f, "\t%s %s(void);", "UnknownType", prop->identifier);
+			break;
+		}
+		case PROP_COLLECTION: {
+			CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
+
+			if(cprop->structtype)
+				fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->structtype, srna->identifier, prop->identifier);
+			else
+				fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
+			break;
+		}
+	}
+
+	fprintf(f, "\n");
+}
+
+static void rna_def_property_funcs_impl_cpp(FILE *f, PropertyDefRNA *dp)
+{
+	PropertyRNA *prop;
+	StructRNA *srna;
+
+	srna= dp->srna;
+	prop= dp->prop;
+
+	if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
+		return;
+
+	switch(prop->type) {
+		case PROP_BOOLEAN: {
+			if(!prop->arraylength)
+				fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
+			else
+				fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->arraylength, prop->identifier);
+			break;
+		}
+		case PROP_INT: {
+			if(!prop->arraylength)
+				fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
+			else
+				fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->arraylength, prop->identifier);
+			break;
+		}
+		case PROP_FLOAT: {
+			if(!prop->arraylength)
+				fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
+			else
+				fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->arraylength, prop->identifier);
+			break;
+		}
+		case PROP_ENUM: {
+			fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", prop->identifier, srna->identifier, prop->identifier);
+
+			break;
+		}
+		case PROP_STRING: {
+			fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
+			break;
+		}
+		case PROP_POINTER: {
+			PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
+
+			if(pprop->structtype)
+				fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", (char*)pprop->structtype, srna->identifier, prop->identifier);
+			else
+				fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
+			break;
+		}
+		case PROP_COLLECTION: {
+			/*CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
+
+			if(cprop->structtype)
+				fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->structtype, srna->identifier, prop->identifier);
+			else
+				fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);*/
+			break;
+		}
+	}
+
+	fprintf(f, "\n");
+}
+
 static const char *rna_find_type(const char *type)
 {
 	StructDefRNA *ds;
@@ -1255,6 +1403,7 @@
 } RNAProcessItem;
 
 RNAProcessItem PROCESS_ITEMS[]= {
+	{"rna_rna.c", RNA_def_rna},
 	{"rna_ID.c", RNA_def_ID},
 	{"rna_texture.c", RNA_def_texture},
 	{"rna_action.c", RNA_def_action},
@@ -1287,7 +1436,6 @@
 	{"rna_pose.c", RNA_def_pose},
 	{"rna_property.c", RNA_def_gameproperty},
 	{"rna_radio.c", RNA_def_radio},
-	{"rna_rna.c", RNA_def_rna},
 	{"rna_scene.c", RNA_def_scene},
 	{"rna_screen.c", RNA_def_screen},
 	{"rna_scriptlink.c", RNA_def_scriptlink},
@@ -1367,6 +1515,8 @@
 
 	fprintf(f, "#include \"RNA_types.h\"\n\n");
 
+	fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
+
 	fprintf(f, "#define FOREACH_BEGIN(property, sptr, itemptr) \\\n");
 	fprintf(f, "	{ \\\n");
 	fprintf(f, "		CollectionPropertyIterator rna_macro_iter; \\\n");
@@ -1393,9 +1543,175 @@
 			rna_def_property_funcs_header(f, dp);
 	}
 
-	fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n");
+	fprintf(f, "#ifdef __cplusplus\n}\n#endif\n\n");
+
+	fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n\n");
 }
 
+static const char *cpp_classes = ""
+"\n"
+"#include <string>\n"
+"\n"
+"namespace RNA {\n"
+"\n"
+"#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
+"	bool sname::identifier(void) { return (bool)sname##_##identifier##_get(&ptr); }\n"
+"\n"
+"#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
+"	Array<int,size> sname::identifier(void) \\\n"
+"		{ Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
+"\n"
+"#define INT_PROPERTY(sname, identifier) \\\n"
+"	int sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
+"\n"
+"#define INT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
+"	Array<int,size> sname::identifier(void) \\\n"
+"		{ Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
+"\n"
+"#define FLOAT_PROPERTY(sname, identifier) \\\n"
+"	float sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
+"\n"
+"#define FLOAT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
+"	Array<float,size> sname::identifier(void) \\\n"
+"		{ Array<float, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
+"\n"
+"#define ENUM_PROPERTY(type, sname, identifier) \\\n"
+"	sname::type sname::identifier(void) { return (type)sname##_##identifier##_get(&ptr); }\n"
+"\n"
+"#define STRING_PROPERTY(sname, identifier) \\\n"
+"	std::string sname::identifier(void) { \\\n"
+"		int len= sname##_##identifier##_length(&ptr); \\\n"
+"		std::string str; str.resize(len); \\\n"
+"		sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
+"\n"
+"#define POINTER_PROPERTY(type, sname, identifier) \\\n"
+"	type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
+"\n"
+"#define COLLECTION_PROPERTY(type, sname, identifier) \\\n"
+"	typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
+"		sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
+"	Collection<sname, type, sname##_##identifier##_begin, \\\n"

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list