7 #ifndef __core_TypeMaster_h__ 8 #define __core_TypeMaster_h__ 16 class FE_DL_EXPORT TypeConversion :
public Counted
25 virtual ~TypeConversion(
void) {}
27 virtual InstanceAllocation operator()(
void *in,
void *&out)
34 TypeConversion(
void): m_name(
"TypeConversion") {}
35 const String& name(
void)
const {
return m_name; }
42 template<
class In,
class Out>
43 class FE_DL_EXPORT NativeConversion :
public TypeConversion
46 InstanceAllocation operator()(
void *in,
void *&out)
49 *
reinterpret_cast<Out *
>(out)=
50 static_cast<Out>(*reinterpret_cast<In *>(in));
55 typedef AutoHashMap< TypeInfo, sp<BaseType> > type_info_map;
56 typedef AutoHashMap< String, sp<BaseType> > string_type_map;
58 typedef AutoHashMap< sp<BaseType>, String > type_string_map;
59 typedef AutoHashMap< sp<BaseType>, sp<TypeConversion> > out_converter_map;
60 typedef AutoHashMap< sp<BaseType>, out_converter_map > in_out_converter_map;
72 BaseType *type(
void) {
return m_pType;}
73 void addType(
BaseType *pType) {m_pType = pType;}
96 void dumpTypes(
void)
const;
101 template<
class Converter,
class In,
class Out>
102 void registerConversion(
void);
104 template<
class In,
class Out>
105 void nativeConversion(
void);
107 void registerConversion(
119 template<
class In,
class Out>
123 std::list<String> &names);
130 void peek(Peeker &peeker);
138 template<
class T,
class Info>
145 const String& name(
void)
const {
return m_name; }
159 type_info_map m_hTypeidMap;
160 string_type_map m_hNameMap;
161 type_string_map m_hTypeMap;
162 in_out_converter_map m_hConverter;
170 return lookupType(
TypeInfo(getTypeId<T>()));
173 template<
class Converter,
class In,
class Out>
174 void TypeMaster::registerConversion(
void)
179 if(spInType.isValid() && spOutType.isValid())
181 registerConversion(spConv,spInType,spOutType);
185 feX(
"fe::TypeMaster::registerConversion",
186 "cannot convert unknown types");
190 template<
class In,
class Out>
191 void TypeMaster::nativeConversion(
void)
193 registerConversion< NativeConversion<In,Out>, In, Out>();
196 template<
class In,
class Out>
201 if(spInType.isValid() && spOutType.isValid())
203 return lookupConversion(spInType,spOutType);
207 feX(
"fe::TypeMaster::lookupConversion",
208 "cannot convert unknown types");
216 return spTypeMaster->assertTypeInternal(
TypeInfo(getTypeId<T>()), spType, name);
223 return assertTypeInternal(
TypeInfo(getTypeId<T>()), spType, name);
229 String name =
"local_rtti_";
230 name.
cat(FE_TYPESTRING(T));
232 return assertTypeInternal(
TypeInfo(getTypeId<T>()), spType, name);
235 template<
class T,
class Info>
241 spReturn = assertTypeInternal(
TypeInfo(getTypeId<T>()), spType, name);
242 spReturn->setInfo(
new Info());
247 class PtrInfo :
public TypeInfoConstructable<sp<T> >
252 class PtrInfo :
public BaseType::Info
255 virtual bool getConstruct(
void)
259 virtual void construct(
void *instance)
263 virtual void destruct(
void *instance)
265 ((
sp<T> *)instance)->~sp<T>();
274 spT = assertType<sp<T> >(name);
275 spT->setInfo(
new PtrInfo<T>());
283 if(spBaseType.isNull())
285 feLog(
"TypeMaster::output bad type\n");
286 return e_unsupported;
289 void*
data = &a_value;
291 std::istringstream istrstrm(a_buffer.
c_str());
292 spBaseType->getInfo()->input(istrstrm,data,
293 BaseType::Info::e_ascii);
302 if(spBaseType.isNull())
304 feLog(
"TypeMaster::output bad type\n");
305 return e_unsupported;
308 void*
data = &a_value;
310 std::ostringstream ostrstrm;
311 if(-1 == spBaseType->getInfo()->output(ostrstrm, data,
312 BaseType::Info::e_ascii))
314 feLog(
"TypeMaster::output ascii write failed\n");
315 return e_writeFailed;
318 a_buffer=ostrstrm.str().
c_str();
Class level locking for thread safety.
Definition: Safe.h:213
const FESTRING_I8 * c_str(void) const
Return the contents of the 8-bit buffer cast as signed bytes.
Definition: String.h:352
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
kernel
Definition: namespace.dox:3
Run time C++ type management.
Definition: TypeMaster.h:66
C++ type_info wrapper.
Definition: Type.h:20
A class to associate functionality with run time types.
Definition: Type.h:571
A class to associate functionality with run time types.
Definition: Type.h:120
Result input(String a_buffer, T &a_value)
serialize String buffer into value
Definition: TypeMaster.h:280
Result output(T &a_value, String &a_buffer)
serialize value into String buffer
Definition: TypeMaster.h:299
String & cat(const char *operand)
Append the current String with the given text.
Definition: String.cc:545
Automatically reference-counted string container.
Definition: String.h:128
Wrapper for std::vector.
Definition: Array.h:21
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192