convert line ends
[canaan.git] / prj / tech / libsrc / sdesc / sdesbase.h
blobf7c9a8d92668a1b076d81e9d1dee005cf72b4a28
1 // $Header: x:/prj/tech/libsrc/sdesc/RCS/sdesbase.h 1.10 1998/05/13 18:50:40 buzzard Exp $
3 #ifndef SDESBASE_H
4 #define SDESBASE_H
5 #include <sdestype.h>
7 //
8 // Generic structure description macros used when actually declaring a
9 // structure description
12 // expands to the actual field in a struct
13 #define FieldSelect(type, field) (((type*)NULL)->field)
15 // expands to the size of a field in a struct
16 #define FieldSize(type, field) (sizeof(FieldSelect(type, field)))
18 // expands to the byte offset of a field in a struct
19 #define FieldOffset(type, field) ((ulong) &FieldSelect(type, field))
21 // expands to the size and the offset of a field in a struct
22 #define FieldLocation(type, field) FieldSize(type, field), FieldOffset(type, field)
24 // for naming enums or bitfields, full sets the constraints, normal lets you do it
25 #define FieldNames(names) sizeof(names)/sizeof(names[0]), sizeof(names)/sizeof(names[0]), names
26 #define FullFieldNames(names) 0, 0, FieldNames(names)
28 // expands to an entire sStructDesc struct
29 #define StructDescBuild(type, flags, fields) \
30 { #type, sizeof(type), flags, sizeof(fields)/sizeof(fields[0]), fields }
33 // Generic structure description enums
36 // sFieldDesc flags
37 enum _eFieldFlags
39 kFieldFlagNone = (0<<0), // no flags (avoid warning)
40 kFieldFlagInvisible = (1<<0), // is this field invisible to the user?
41 kFieldFlagNotEdit = (1<<1), // is this field not editable by the user?
42 kFieldFlagIrrelevant = (1<<2), // is this field irrelevant?
43 kFieldFlagUIRanged = (1<<3), // is the value ranged?
44 kFieldFlagUIWrap = (1<<4), // does the value wrap around at the ends?
45 kFieldFlagUnsigned = (1<<5), // is this field unsigned?
46 kFieldFlagHex = (1<<6), // is this field displayed as hex?
49 // sStructDesc flags
50 enum _eStructFlags
52 kStructFlagNone = (0<<0), // no flags (avoid warning)
53 kStructFlagInvisible = (1<<0), // is this struct invisible to the user?
54 kStructFlagNotEdit = (1<<1), // is this struct not editable by the user?
57 // atomic field types // Type
58 enum _eFieldType
60 kFieldTypeInt, // signed integer
61 kFieldTypeBool, // boolean
62 kFieldTypeShort, // signed short
63 kFieldTypeBits, // bitmask (max = first bit, min = last bit, data = array of string names of bits)
64 kFieldTypeEnum, // enum (actually integer)
65 kFieldTypeString, // character string
66 kFieldTypeStringPtr, // character pointer
67 kFieldTypeVoidPtr, // void pointer
68 kFieldTypePoint, // struct Point (x,y)
69 kFieldTypeVector, // struct mxs_vector (x,y,z)
70 kFieldTypeFloat, // float
71 kFieldTypeFix, // fix (integer interpreted as 16.16)
72 kFieldTypeFixVec, // vector of fixes
76 // Generic structure description structures
80 // the actual field description
81 struct sFieldDesc
83 char name[32]; // name of field
84 eFieldType type; // type of field
85 ulong size; // size in bytes of field
86 ulong offset; // offset in bytes of field
87 eFieldFlags flags; // field flags
88 int min; // min value if ranged
89 int max; // max value if ranged
90 ulong datasize; // number of data elements
91 void* data; // actual data elements (could be enum names
92 // or whatever)
95 // the actual structure description
96 struct sStructDesc
98 char name[32]; // name of struct
99 ulong size; // size in bytes of struct
100 eStructFlags flags; // struct flags
101 int nfields; // number of fields in struct
102 sFieldDesc* fields; // actual field descriptions
105 // Build a complete structdesc for a single-field data type
106 #define StructDescDefineSingleton(varname,type,field,flags) \
107 sFieldDesc varname##_fields = { "", field, sizeof(type), 0, flags }; \
108 sStructDesc varname = { #type, sizeof(type), kStructFlagNone, 1, &(varname##_fields) }
111 #endif // SDESBASE_H