Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_rna.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 557d472afef09e13314460b593b3917205098aa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
/**
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Contributor(s): Blender Foundation (2008).
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#include <stdlib.h>

#include "DNA_ID.h"

#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_types.h"

#include "rna_internal.h"

#ifdef RNA_RUNTIME

#include "BLI_ghash.h"

/* Struct */

static void rna_Struct_identifier_get(PointerRNA *ptr, char *value)
{
	strcpy(value, ((StructRNA*)ptr->data)->identifier);
}

static int rna_Struct_identifier_length(PointerRNA *ptr)
{
	return strlen(((StructRNA*)ptr->data)->identifier);
}

static void rna_Struct_description_get(PointerRNA *ptr, char *value)
{
	strcpy(value, ((StructRNA*)ptr->data)->description);
}

static int rna_Struct_description_length(PointerRNA *ptr)
{
	return strlen(((StructRNA*)ptr->data)->description);
}

static void rna_Struct_name_get(PointerRNA *ptr, char *value)
{
	strcpy(value, ((StructRNA*)ptr->data)->name);
}

static int rna_Struct_name_length(PointerRNA *ptr)
{
	return strlen(((StructRNA*)ptr->data)->name);
}

static PointerRNA rna_Struct_base_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((StructRNA*)ptr->data)->base);
}

static PointerRNA rna_Struct_nested_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((StructRNA*)ptr->data)->nested);
}

static PointerRNA rna_Struct_name_property_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_Property, ((StructRNA*)ptr->data)->nameproperty);
}

/* Struct property iteration. This is quite complicated, the purpose is to
 * iterate over properties of all inheritance levels, and for each struct to
 * also iterator over id properties not known by RNA. */

static int rna_idproperty_known(CollectionPropertyIterator *iter, void *data)
{
	IDProperty *idprop= (IDProperty*)data;
	PropertyRNA *prop;
	StructRNA *ptype= iter->builtin_parent.type;

	/* function to skip any id properties that are already known by RNA,
	 * for the second loop where we go over unknown id properties */

	for(prop= ptype->cont.properties.first; prop; prop=prop->next)
		if(strcmp(prop->identifier, idprop->name) == 0)
			return 1;
	
	return 0;
}

static int rna_property_builtin(CollectionPropertyIterator *iter, void *data)
{
	PropertyRNA *prop= (PropertyRNA*)data;

	/* function to skip builtin rna properties */

	return (prop->flag & PROP_BUILTIN);
}

static int rna_function_builtin(CollectionPropertyIterator *iter, void *data)
{
	FunctionRNA *func= (FunctionRNA*)data;

	/* function to skip builtin rna functions */

	return (func->flag & FUNC_BUILTIN);
}

static void rna_inheritance_next_level_restart(CollectionPropertyIterator *iter, IteratorSkipFunc skip, int funcs)
{
	/* RNA struct inheritance */
	while(!iter->valid && iter->level > 0) {
		StructRNA *srna;
		int i;

		srna= (StructRNA*)iter->parent.data;
		iter->level--;
		for(i=iter->level; i>0; i--)
			srna= srna->base;

		rna_iterator_listbase_end(iter);

		if (funcs)
			rna_iterator_listbase_begin(iter, &srna->functions, skip);
		else
			rna_iterator_listbase_begin(iter, &srna->cont.properties, skip);
	}
}

static void rna_inheritance_properties_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
{
	rna_iterator_listbase_begin(iter, lb, skip);
	rna_inheritance_next_level_restart(iter, skip, 0);
}

static void rna_inheritance_properties_listbase_next(CollectionPropertyIterator *iter, IteratorSkipFunc skip)
{
	rna_iterator_listbase_next(iter);
	rna_inheritance_next_level_restart(iter, skip, 0);
}

static void rna_inheritance_functions_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
{
	rna_iterator_listbase_begin(iter, lb, skip);
	rna_inheritance_next_level_restart(iter, skip, 1);
}

static void rna_inheritance_functions_listbase_next(CollectionPropertyIterator *iter, IteratorSkipFunc skip)
{
	rna_iterator_listbase_next(iter);
	rna_inheritance_next_level_restart(iter, skip, 1);
}

static void rna_Struct_properties_next(CollectionPropertyIterator *iter)
{
	ListBaseIterator *internal= iter->internal;
	IDProperty *group;

	if(internal->flag) {
		/* id properties */
		rna_iterator_listbase_next(iter);
	}
	else {
		/* regular properties */
		rna_inheritance_properties_listbase_next(iter, rna_property_builtin);

		/* try id properties */
		if(!iter->valid) {
			group= RNA_struct_idproperties(&iter->builtin_parent, 0);

			if(group) {
				rna_iterator_listbase_end(iter);
				rna_iterator_listbase_begin(iter, &group->data.group, rna_idproperty_known);
				internal= iter->internal;
				internal->flag= 1;
			}
		}
	}
}

static void rna_Struct_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	StructRNA *srna;

	/* here ptr->data should always be the same as iter->parent.type */
	srna= (StructRNA *)ptr->data;

	while(srna->base) {
		iter->level++;
		srna= srna->base;
	}

	rna_inheritance_properties_listbase_begin(iter, &srna->cont.properties, rna_property_builtin);
}

static PointerRNA rna_Struct_properties_get(CollectionPropertyIterator *iter)
{
	ListBaseIterator *internal= iter->internal;

	/* we return either PropertyRNA* or IDProperty*, the rna_access.c
	 * functions can handle both as PropertyRNA* with some tricks */
	return rna_pointer_inherit_refine(&iter->parent, &RNA_Property, internal->link);
}

static void rna_Struct_functions_next(CollectionPropertyIterator *iter)
{
	rna_inheritance_functions_listbase_next(iter, rna_function_builtin);
}

static void rna_Struct_functions_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	StructRNA *srna;

	/* here ptr->data should always be the same as iter->parent.type */
	srna= (StructRNA *)ptr->data;

	while(srna->base) {
		iter->level++;
		srna= srna->base;
	}

	rna_inheritance_functions_listbase_begin(iter, &srna->functions, rna_function_builtin);
}

static PointerRNA rna_Struct_functions_get(CollectionPropertyIterator *iter)
{
	ListBaseIterator *internal= iter->internal;

	/* we return either PropertyRNA* or IDProperty*, the rna_access.c
	 * functions can handle both as PropertyRNA* with some tricks */
	return rna_pointer_inherit_refine(&iter->parent, &RNA_Function, internal->link);
}

/* Builtin properties iterator re-uses the Struct properties iterator, only
 * difference is that we need to set the ptr data to the type of the struct
 * whose properties we want to iterate over. */

void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	PointerRNA newptr;

	/* we create a new pointer with the type as the data */
	newptr.type= &RNA_Struct;
	newptr.data= ptr->type;

	if(ptr->type->flag & STRUCT_ID)
		newptr.id.data= ptr->data;
	else
		newptr.id.data= NULL;

	iter->parent= newptr;
	iter->builtin_parent = *ptr;

	rna_Struct_properties_begin(iter, &newptr);
}

void rna_builtin_properties_next(CollectionPropertyIterator *iter)
{
	rna_Struct_properties_next(iter);
}

PointerRNA rna_builtin_properties_get(CollectionPropertyIterator *iter)
{
	return rna_Struct_properties_get(iter);
}

PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key)
{
	StructRNA *srna;
	PropertyRNA *prop;
	IDProperty *group, *idp;
	PointerRNA propptr;

	memset(&propptr, 0, sizeof(propptr));
	srna= ptr->type;

	do {
		if(srna->cont.prophash) {
			prop= BLI_ghash_lookup(srna->cont.prophash, (void*)key);

			if(prop) {
				propptr.type= &RNA_Property;
				propptr.data= prop;
				return propptr;
			}
		}

		for(prop=srna->cont.properties.first; prop; prop=prop->next) {
			if(!(prop->flag & PROP_BUILTIN) && strcmp(prop->identifier, key)==0) {
				propptr.type= &RNA_Property;
				propptr.data= prop;
				return propptr;
			}
		}
	} while((srna=srna->base));

	if(ptr->data) {
		group= RNA_struct_idproperties(ptr, 0);

		if(group) {
			for(idp=group->data.group.first; idp; idp=idp->next) {
				if(strcmp(idp->name, key) == 0) {
					propptr.type= &RNA_Property;
					propptr.data= idp;
					return propptr;
				}
			}
		}
	}

	return propptr;
}

PointerRNA rna_builtin_type_get(PointerRNA *ptr)
{
	return rna_pointer_inherit_refine(ptr, &RNA_Struct, ptr->type);
}

/* Property */

static StructRNA *rna_Property_refine(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;

	rna_idproperty_check(&prop, ptr); /* XXX ptr? */

	switch(prop->type) {
		case PROP_BOOLEAN: return &RNA_BooleanProperty;
		case PROP_INT: return &RNA_IntProperty;
		case PROP_FLOAT: return &RNA_FloatProperty;
		case PROP_STRING: return &RNA_StringProperty;
		case PROP_ENUM: return &RNA_EnumProperty;
		case PROP_POINTER: return &RNA_PointerProperty;
		case PROP_COLLECTION: return &RNA_CollectionProperty;
		default: return &RNA_Property;
	}
}

static void rna_Property_identifier_get(PointerRNA *ptr, char *value)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	strcpy(value, ((PropertyRNA*)prop)->identifier);
}

static int rna_Property_identifier_length(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return strlen(prop->identifier);
}

static void rna_Property_name_get(PointerRNA *ptr, char *value)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	strcpy(value, prop->name);
}

static int rna_Property_name_length(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return strlen(prop->name);
}

static void rna_Property_description_get(PointerRNA *ptr, char *value)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	strcpy(value, prop->description);
}

static int rna_Property_description_length(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return strlen(prop->description);
}

static int rna_Property_type_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return prop->type;
}

static int rna_Property_subtype_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return prop->subtype;
}

static int rna_Property_editable_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	return RNA_property_editable(ptr, prop);
}

static int rna_Property_array_length_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return prop->arraylength;
}

static int rna_Property_registered_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	return prop->flag & PROP_REGISTER;
}

static int rna_Property_registered_optional_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	return prop->flag & PROP_REGISTER_OPTIONAL;
}

static int rna_IntProperty_hard_min_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((IntPropertyRNA*)prop)->hardmin;
}

static int rna_IntProperty_hard_max_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((IntPropertyRNA*)prop)->hardmax;
}

static int rna_IntProperty_soft_min_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((IntPropertyRNA*)prop)->softmin;
}

static int rna_IntProperty_soft_max_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((IntPropertyRNA*)prop)->softmax;
}

static int rna_IntProperty_step_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((IntPropertyRNA*)prop)->step;
}

static float rna_FloatProperty_hard_min_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((FloatPropertyRNA*)prop)->hardmin;
}

static float rna_FloatProperty_hard_max_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((FloatPropertyRNA*)prop)->hardmax;
}

static float rna_FloatProperty_soft_min_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((FloatPropertyRNA*)prop)->softmin;
}

static float rna_FloatProperty_soft_max_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((FloatPropertyRNA*)prop)->softmax;
}

static float rna_FloatProperty_step_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((FloatPropertyRNA*)prop)->step;
}

static int rna_FloatProperty_precision_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((FloatPropertyRNA*)prop)->precision;
}

static int rna_StringProperty_max_length_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return ((StringPropertyRNA*)prop)->maxlength;
}

static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	EnumPropertyRNA *eprop;

	rna_idproperty_check(&prop, ptr);
	eprop= (EnumPropertyRNA*)prop;

	rna_iterator_array_begin(iter, (void*)eprop->item, sizeof(eprop->item[0]), eprop->totitem, NULL);
}

static void rna_EnumPropertyItem_identifier_get(PointerRNA *ptr, char *value)
{
	strcpy(value, ((EnumPropertyItem*)ptr->data)->identifier);
}

static int rna_EnumPropertyItem_identifier_length(PointerRNA *ptr)
{
	return strlen(((EnumPropertyItem*)ptr->data)->identifier);
}

static void rna_EnumPropertyItem_name_get(PointerRNA *ptr, char *value)
{
	strcpy(value, ((EnumPropertyItem*)ptr->data)->name);
}

static int rna_EnumPropertyItem_name_length(PointerRNA *ptr)
{
	return strlen(((EnumPropertyItem*)ptr->data)->name);
}

static void rna_EnumPropertyItem_description_get(PointerRNA *ptr, char *value)
{
	EnumPropertyItem *eprop= (EnumPropertyItem*)ptr->data;

	if(eprop->description)
		strcpy(value, eprop->description);
	else
		value[0]= '\0';
}

static int rna_EnumPropertyItem_description_length(PointerRNA *ptr)
{
	EnumPropertyItem *eprop= (EnumPropertyItem*)ptr->data;

	if(eprop->description)
		return strlen(eprop->description);
	else
		return 0;
}

static int rna_EnumPropertyItem_value_get(PointerRNA *ptr)
{
	return ((EnumPropertyItem*)ptr->data)->value;
}

static PointerRNA rna_PointerProperty_fixed_type_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((PointerPropertyRNA*)prop)->type);
}

static PointerRNA rna_CollectionProperty_fixed_type_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((CollectionPropertyRNA*)prop)->type);
}

/* Function */

static void rna_Function_identifier_get(PointerRNA *ptr, char *value)
{
	strcpy(value, ((FunctionRNA*)ptr->data)->identifier);
}

static int rna_Function_identifier_length(PointerRNA *ptr)
{
	return strlen(((FunctionRNA*)ptr->data)->identifier);
}

static void rna_Function_description_get(PointerRNA *ptr, char *value)
{
	strcpy(value, ((FunctionRNA*)ptr->data)->description);
}

static int rna_Function_description_length(PointerRNA *ptr)
{
	return strlen(((FunctionRNA*)ptr->data)->description);
}

static void rna_Function_parameters_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	rna_iterator_listbase_begin(iter, &((FunctionRNA*)ptr->data)->cont.properties, rna_property_builtin);
}

static int rna_Function_registered_get(PointerRNA *ptr)
{
	FunctionRNA *func= (FunctionRNA*)ptr->data;
	return func->flag & FUNC_REGISTER;
}

static int rna_Function_registered_optional_get(PointerRNA *ptr)
{
	FunctionRNA *func= (FunctionRNA*)ptr->data;
	return func->flag & FUNC_REGISTER_OPTIONAL;
}

/* Blender RNA */

static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	rna_iterator_listbase_begin(iter, &((BlenderRNA*)ptr->data)->structs, NULL);
}

#else

static void rna_def_struct(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "Struct", NULL);
	RNA_def_struct_ui_text(srna, "Struct Definition", "RNA structure definition");
	RNA_def_struct_ui_icon(srna, ICON_RNA);

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Struct_name_get", "rna_Struct_name_length", NULL);
	RNA_def_property_ui_text(prop, "Name", "Human readable name.");

	prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Struct_identifier_get", "rna_Struct_identifier_length", NULL);
	RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting.");
	RNA_def_struct_name_property(srna, prop);
	
	prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Struct_description_get", "rna_Struct_description_length", NULL);
	RNA_def_property_ui_text(prop, "Description", "Description of the Struct's purpose.");
	
	prop= RNA_def_property(srna, "base", PROP_POINTER, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "Struct");
	RNA_def_property_pointer_funcs(prop, "rna_Struct_base_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Base", "Struct definition this is derived from.");

	prop= RNA_def_property(srna, "nested", PROP_POINTER, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "Struct");
	RNA_def_property_pointer_funcs(prop, "rna_Struct_nested_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Nested", "Struct in which this struct is always nested, and to which it logically belongs.");

	prop= RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "StringProperty");
	RNA_def_property_pointer_funcs(prop, "rna_Struct_name_property_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Name Property", "Property that gives the name of the struct.");

	prop= RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "Property");
	RNA_def_property_collection_funcs(prop, "rna_Struct_properties_begin", "rna_Struct_properties_next", "rna_iterator_listbase_end", "rna_Struct_properties_get", 0, 0, 0, 0, 0);
	RNA_def_property_ui_text(prop, "Properties", "Properties in the struct.");

	prop= RNA_def_property(srna, "functions", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "Function");
	RNA_def_property_collection_funcs(prop, "rna_Struct_functions_begin", "rna_Struct_functions_next", "rna_iterator_listbase_end", "rna_Struct_functions_get", 0, 0, 0, 0, 0);
	RNA_def_property_ui_text(prop, "Functions", "");
}

static void rna_def_property(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	static EnumPropertyItem type_items[] = {
		{PROP_BOOLEAN, "BOOLEAN", 0, "Boolean", ""},
		{PROP_INT, "INT", 0, "Integer", ""},
		{PROP_FLOAT, "FLOAT", 0, "Float", ""},
		{PROP_STRING, "STRING", 0, "String", ""},
		{PROP_ENUM, "ENUM", 0, "Enumeration", ""},
		{PROP_POINTER, "POINTER", 0, "Pointer", ""},
		{PROP_COLLECTION, "COLLECTION", 0, "Collection", ""},
		{0, NULL, 0, NULL, NULL}};
	static EnumPropertyItem subtype_items[] = {
		{PROP_NONE, "NONE", 0, "None", ""},
		{PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned Number", ""},
		{PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
		{PROP_DIRPATH, "DIRECTORY_PATH", 0, "Directory Path", ""},
		{PROP_COLOR, "COLOR", 0, "Color", ""},
		{PROP_VECTOR, "VECTOR", 0, "Vector", ""},
		{PROP_MATRIX, "MATRIX", 0, "Matrix", ""},
		{PROP_ROTATION, "ROTATION", 0, "Rotation", ""},
		{PROP_NEVER_NULL, "NEVER_NULL", 0, "Never Null", ""},
		{PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
		{0, NULL, 0, NULL, NULL}};

	srna= RNA_def_struct(brna, "Property", NULL);
	RNA_def_struct_ui_text(srna, "Property Definition", "RNA property definition.");
	RNA_def_struct_refine_func(srna, "rna_Property_refine");
	RNA_def_struct_ui_icon(srna, ICON_RNA);

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Property_name_get", "rna_Property_name_length", NULL);
	RNA_def_property_ui_text(prop, "Name", "Human readable name.");

	prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Property_identifier_get", "rna_Property_identifier_length", NULL);
	RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting.");
	RNA_def_struct_name_property(srna, prop);
		
	prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Property_description_get", "rna_Property_description_length", NULL);
	RNA_def_property_ui_text(prop, "Description", "Description of the property for tooltips.");

	prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_enum_items(prop, type_items);
	RNA_def_property_enum_funcs(prop, "rna_Property_type_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Type", "Data type of the property.");

	prop= RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_enum_items(prop, subtype_items);
	RNA_def_property_enum_funcs(prop, "rna_Property_subtype_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Subtype", "Semantic interpretation of the property.");

	prop= RNA_def_property(srna, "editable", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_boolean_funcs(prop, "rna_Property_editable_get", NULL);
	RNA_def_property_ui_text(prop, "Editable", "Property is editable through RNA.");

	prop= RNA_def_property(srna, "registered", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_boolean_funcs(prop, "rna_Property_registered_get", NULL);
	RNA_def_property_ui_text(prop, "Registered", "Property is registerd as part of type registration.");

	prop= RNA_def_property(srna, "registered_optional", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_boolean_funcs(prop, "rna_Property_registered_optional_get", NULL);
	RNA_def_property_ui_text(prop, "Registered Optionally", "Property is optionally registerd as part of type registration.");
}

static void rna_def_function(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "Function", NULL);
	RNA_def_struct_ui_text(srna, "Function Definition", "RNA function definition");
	RNA_def_struct_ui_icon(srna, ICON_RNA);

	prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Function_identifier_get", "rna_Function_identifier_length", NULL);
	RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting.");
	RNA_def_struct_name_property(srna, prop);

	prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_Function_description_get", "rna_Function_description_length", NULL);
	RNA_def_property_ui_text(prop, "Description", "Description of the Function's purpose.");

	prop= RNA_def_property(srna, "parameters", PROP_COLLECTION, PROP_NONE);
	/*RNA_def_property_clear_flag(prop, PROP_EDITABLE);*/
	RNA_def_property_struct_type(prop, "Property");
	RNA_def_property_collection_funcs(prop, "rna_Function_parameters_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0);
	RNA_def_property_ui_text(prop, "Parameters", "Parameters for the function.");

	prop= RNA_def_property(srna, "registered", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_boolean_funcs(prop, "rna_Function_registered_get", NULL);
	RNA_def_property_ui_text(prop, "Registered", "Function is registerd as callback as part of type registration.");

	prop= RNA_def_property(srna, "registered_optional", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_boolean_funcs(prop, "rna_Function_registered_optional_get", NULL);
	RNA_def_property_ui_text(prop, "Registered Optionally", "Function is optionally registerd as callback part of type registration.");
}

static void rna_def_number_property(StructRNA *srna, PropertyType type)
{
	PropertyRNA *prop;

	prop= RNA_def_property(srna, "array_length", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_Property_array_length_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Array Length", "Maximum length of the array, 0 means unlimited.");

	if(type == PROP_BOOLEAN)
		return;

	prop= RNA_def_property(srna, "hard_min", type, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_min_get", NULL, NULL);
	else RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_min_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Hard Minimum", "Minimum value used by buttons.");

	prop= RNA_def_property(srna, "hard_max", type, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_max_get", NULL, NULL);
	else RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_max_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Hard Maximum", "Maximum value used by buttons.");

	prop= RNA_def_property(srna, "soft_min", type, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_min_get", NULL, NULL);
	else RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_min_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Soft Minimum", "Minimum value used by buttons.");

	prop= RNA_def_property(srna, "soft_max", type, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_max_get", NULL, NULL);
	else RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_max_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Soft Maximum", "Maximum value used by buttons.");

	prop= RNA_def_property(srna, "step", type, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_step_get", NULL, NULL);
	else RNA_def_property_float_funcs(prop, "rna_FloatProperty_step_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Step", "Step size used by number buttons, for floats 1/100th of the step size.");

	if(type == PROP_FLOAT) {
		prop= RNA_def_property(srna, "precision", PROP_INT, PROP_UNSIGNED);
		RNA_def_property_clear_flag(prop, PROP_EDITABLE);
		RNA_def_property_int_funcs(prop, "rna_FloatProperty_precision_get", NULL, NULL);
		RNA_def_property_ui_text(prop, "Precision", "Number of digits after the dot used by buttons.");
	}
}

static void rna_def_string_property(StructRNA *srna)
{
	PropertyRNA *prop;

	prop= RNA_def_property(srna, "max_length", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Maximum Length", "Maximum length of the string, 0 means unlimited.");
}

static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna)
{
	PropertyRNA *prop;

	prop= RNA_def_property(srna, "items", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "EnumPropertyItem");
	RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0, 0);
	RNA_def_property_ui_text(prop, "Items", "Possible values for the property.");

	srna= RNA_def_struct(brna, "EnumPropertyItem", NULL);
	RNA_def_struct_ui_text(srna, "Enum Item Definition", "Definition of a choice in an RNA enum property.");
	RNA_def_struct_ui_icon(srna, ICON_RNA);

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_name_get", "rna_EnumPropertyItem_name_length", NULL);
	RNA_def_property_ui_text(prop, "Name", "Human readable name.");

	prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_description_get", "rna_EnumPropertyItem_description_length", NULL);
	RNA_def_property_ui_text(prop, "Description", "Description of the item's purpose.");

	prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_identifier_get", "rna_EnumPropertyItem_identifier_length", NULL);
	RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting.");
	RNA_def_struct_name_property(srna, prop);

	prop= RNA_def_property(srna, "value", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_EnumPropertyItem_value_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Value", "Value of the item.");
}

static void rna_def_pointer_property(StructRNA *srna, PropertyType type)
{
	PropertyRNA *prop;

	prop= RNA_def_property(srna, "fixed_type", PROP_POINTER, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "Struct");
	if(type == PROP_POINTER)
		RNA_def_property_pointer_funcs(prop, "rna_PointerProperty_fixed_type_get", NULL, NULL);
	else
		RNA_def_property_pointer_funcs(prop, "rna_CollectionProperty_fixed_type_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Pointer Type", "Fixed pointer type, empty if variable type.");
}

void RNA_def_rna(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	/* Struct*/
	rna_def_struct(brna);

	/* Property */
	rna_def_property(brna);

	/* BooleanProperty */
	srna= RNA_def_struct(brna, "BooleanProperty", "Property");
	RNA_def_struct_ui_text(srna, "Boolean Definition", "RNA boolean property definition.");
	rna_def_number_property(srna, PROP_BOOLEAN);

	/* IntProperty */
	srna= RNA_def_struct(brna, "IntProperty", "Property");
	RNA_def_struct_ui_text(srna, "Int Definition", "RNA integer number property definition.");
	rna_def_number_property(srna, PROP_INT);

	/* FloatProperty */
	srna= RNA_def_struct(brna, "FloatProperty", "Property");
	RNA_def_struct_ui_text(srna, "Float Definition", "RNA floating pointer number property definition.");
	rna_def_number_property(srna, PROP_FLOAT);

	/* StringProperty */
	srna= RNA_def_struct(brna, "StringProperty", "Property");
	RNA_def_struct_ui_text(srna, "String Definition", "RNA text string property definition.");
	rna_def_string_property(srna);

	/* EnumProperty */
	srna= RNA_def_struct(brna, "EnumProperty", "Property");
	RNA_def_struct_ui_text(srna, "Enum Definition", "RNA enumeration property definition, to choose from a number of predefined options.");
	rna_def_enum_property(brna, srna);

	/* PointerProperty */
	srna= RNA_def_struct(brna, "PointerProperty", "Property");
	RNA_def_struct_ui_text(srna, "Pointer Definition", "RNA pointer property to point to another RNA struct.");
	rna_def_pointer_property(srna, PROP_POINTER);

	/* CollectionProperty */
	srna= RNA_def_struct(brna, "CollectionProperty", "Property");
	RNA_def_struct_ui_text(srna, "Collection Definition", "RNA collection property to define lists, arrays and mappings.");
	rna_def_pointer_property(srna, PROP_COLLECTION);
	
	/* Function */
	rna_def_function(brna);

	/* Blender RNA */
	srna= RNA_def_struct(brna, "BlenderRNA", NULL);
	RNA_def_struct_ui_text(srna, "Blender RNA", "Blender RNA structure definitions.");
	RNA_def_struct_ui_icon(srna, ICON_RNA);

	prop= RNA_def_property(srna, "structs", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_struct_type(prop, "Struct");
	RNA_def_property_collection_funcs(prop, "rna_BlenderRNA_structs_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0);
	RNA_def_property_ui_text(prop, "Structs", "");
}

#endif