00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUFO_ATTR_H
00019 #define CUFO_ATTR_H
00020
00021 #include <cufo/fwd.h>
00022 #include <cucon/fwd.h>
00023 #include <cu/idr.h>
00024 #include <cu/box.h>
00025
00026 CU_BEGIN_DECLARATIONS
00027
00028
00029
00030 typedef enum {
00031 cufo_attrtype_fixed,
00032 cufo_attrtype_enum,
00033 cufo_attrtype_cstr,
00034 cufo_attrtype_int,
00035 } cufo_attrtype_t;
00036
00037 struct cufo_attr
00038 {
00039 cufo_namespace_t ns;
00040 cu_idr_t idr;
00041 cufo_attrtype_t type;
00042 union {
00043 char const *fixed_value;
00044 char const *(*enum_name)(int);
00045 } extra;
00046 };
00047
00048 void cufo_attr_init(cufo_attr_t attr, cufo_namespace_t ns,
00049 char const *name, cufo_attrtype_t type);
00050
00051 void cufo_attr_init_fixed(cufo_attr_t attr, cufo_namespace_t ns,
00052 char const *name, char const *val);
00053
00054 void cufo_attr_init_enum(cufo_attr_t attr, cufo_namespace_t ns,
00055 char const *name, char const *(*enum_name)(int));
00056
00057 CU_SINLINE char const *
00058 cufo_attr_name(cufo_attr_t attr)
00059 { return cu_idr_to_cstr(attr->idr); }
00060
00061 CU_SINLINE cufo_attrtype_t
00062 cufo_attr_type(cufo_attr_t attr)
00063 { return attr->type; }
00064
00065 CU_SINLINE cu_box_t cufoP_cktype_int(int i)
00066 { return cu_box_int(i); }
00067 CU_SINLINE cu_box_t cufoP_cktype_cstr(char const *s)
00068 { return cu_box_ptr(char *, (char *)s); }
00069
00070 #define CUFO_ATTR_INT(attr, i) attr, cufoP_cktype_int(i)
00071 #define CUFO_ATTR_CSTR(attr, s) attr, cufoP_cktype_cstr(s)
00072 #define CUFO_ATTR_ENUM(attr, i) attr, cufoP_cktype_int(i)
00073
00074 struct cufo_attrbind
00075 {
00076 cufo_attr_t attr;
00077 cu_box_t value;
00078 };
00079
00080
00081 CU_END_DECLARATIONS
00082
00083 #endif