7 #ifndef __core_Type_h__ 8 #define __core_Type_h__ 11 #define FE_TYPE_STORE_NAME (FE_CODEGEN<=FE_DEBUG && !FE_COUNTED_STORE_TRACKER) 23 class not_initialized {};
30 void assign(
void) { operator=(getTypeId<X>()); }
32 const fe_type_info &ref(
void)
const;
37 bool operator<(
const TypeInfo &other)
const;
38 bool operator>(
const TypeInfo &other)
const;
39 bool operator>=(
const TypeInfo &other)
const;
40 bool operator<=(
const TypeInfo &other)
const;
42 bool isValid(
void)
const;
44 const fe_type_info *m_pTypeInfo;
47 class FE_DL_EXPORT BaseTypeVector:
57 virtual ~BaseTypeVector(
void)
63 virtual void resize(
unsigned int a_size) {}
66 void *raw_at(
unsigned int a_index)
68 return (
void *)((
char *)m_base + m_size*a_index);
71 #if FE_COUNTED_STORE_TRACKER 72 const String verboseName(
void)
const 73 {
return "BaseTypeVector "+name(); }
76 unsigned int size(
void)
const {
return m_size; }
123 class FE_DL_PUBLIC FE_CORE_PORT Info:
135 #if FE_COUNTED_STORE_TRACKER 136 setName(
"BaseType::Info");
138 #if FE_CODEGEN<=FE_DEBUG && FE_OS==FE_LINUX && FE_HEAP_CHECKABLE 140 if((
void*)
this>(
void*)¤t_stack)
141 feX(
"fe::BaseType::Info::Info",
142 "Info object not on stack");
146 virtual ~Info(
void) {}
147 virtual bool getConstruct(
void) {
return false; }
148 virtual void construct(
void *instance) {}
149 virtual void destruct(
void *instance) {}
150 virtual BWORD copy(
void *instance,
const void* source)
152 if(iosize()==c_implicit)
154 memcpy(instance,source,iosize());
157 virtual IWORD output( std::ostream &ostrm,
void *instance,
158 t_serialMode mode) = 0;
159 virtual void input( std::istream &istrm,
void *instance,
160 t_serialMode mode) = 0;
161 virtual String print(
void *instance) {
return String(); }
162 virtual IWORD iosize(
void) {
return c_implicit; }
163 virtual FE_UWORD alignment(
void) {
return 0; }
166 static FE_DL_PUBLIC
const IWORD c_implicit;
169 static FE_DL_PUBLIC
const IWORD c_explicit;
170 static FE_DL_PUBLIC
const IWORD c_noascii;
171 static FE_DL_PUBLIC
const IWORD c_ascii;
173 #if FE_COUNTED_STORE_TRACKER 174 const String verboseName(
void)
const 175 {
return "BaseType::Info "+name(); }
181 virtual FE_UWORD size(
void)
const;
182 virtual void assign(
void *lvalue,
void *rvalue) =0;
183 virtual bool equiv(
void *a_a,
void *a_b) =0;
184 virtual void setInfo(
const sp<Info> &spInfo);
185 virtual void setInfo(Info *pInfo);
188 virtual bool getConstruct(
void)
const;
189 virtual void construct(
void *instance);
190 virtual void destruct(
void *instance);
191 virtual BWORD copy(
void *instance,
const void* source);
196 #if FE_COUNTED_STORE_TRACKER || FE_TYPE_STORE_NAME 197 const String verboseName(
void)
const {
return "Type<"+name()+
">"; }
200 #if FE_TYPE_STORE_NAME 202 const String& name(
void)
const {
return m_storedName; }
203 void setName(
const String& a_name)
204 { m_storedName=a_name; }
217 class FE_DL_EXPORT TypeInfoInitialized :
public BaseType::Info
220 TypeInfoInitialized(
void)
222 #if FE_COUNTED_STORE_TRACKER 223 setName(FE_TYPESTRING(T));
226 virtual ~TypeInfoInitialized(
void) { }
227 virtual bool getConstruct(
void) {
return true; }
228 virtual void construct(
void *instance) { *((T *)instance)=T(0); }
229 virtual IWORD output( std::ostream &ostrm,
void *instance,
232 if(mode == e_binary) {
return 0; }
233 else {
return c_noascii; }
235 virtual void input( std::istream &istrm,
void *instance,
236 t_serialMode mode) { }
237 virtual IWORD iosize(
void) {
return sizeof(T); }
241 class FE_DL_EXPORT TypeInfoConstructable :
public BaseType::Info
244 TypeInfoConstructable(
void)
246 #if FE_COUNTED_STORE_TRACKER 247 setName(FE_TYPESTRING(T));
250 virtual ~TypeInfoConstructable(
void) { }
251 virtual bool getConstruct(
void) {
return true; }
252 virtual void construct(
void *instance) {
new(instance)T; }
253 virtual void destruct(
void *instance) { ((T *)instance)->~T(); }
254 virtual IWORD output( std::ostream &ostrm,
void *instance,
257 if(mode == e_binary) {
return 0; }
258 else {
return c_noascii; }
260 virtual void input( std::istream &istrm,
void *instance,
261 t_serialMode mode) { }
264 class FE_DL_EXPORT BaseTypeInfoArray:
269 BaseTypeInfoArray(
void) {}
270 virtual ~BaseTypeInfoArray(
void) {}
273 virtual void resize(I32 a_size,
void *instance) =0;
276 virtual I32 access(
void*& a_rpBuffer,
void *instance) =0;
281 class FE_DL_EXPORT TypeInfoArray:
282 public TypeInfoConstructable<T>,
283 public BaseTypeInfoArray
286 TypeInfoArray(
void) {}
287 virtual ~TypeInfoArray(
void) {}
289 virtual void resize(I32 a_size,
void *instance)
291 if(!instance)
return;
292 T &v = *(T *)instance;
296 virtual I32 access(
void*& a_rpBuffer,
void *instance)
298 if(!instance)
return -1;
299 T &v = *(T *)instance;
306 class FE_DL_EXPORT TypeInfoMemcpyIO :
public BaseType::Info
309 virtual IWORD output(std::ostream &ostrm,
void *instance, t_serialMode mode);
310 virtual void input(std::istream &istrm,
void *instance, t_serialMode mode);
311 virtual IWORD iosize(
void);
316 class FE_DL_EXPORT TypeVector :
public BaseTypeVector
325 virtual ~TypeVector(
void)
329 deallocate(m_vector);
333 virtual void resize(
unsigned int a_size)
335 if(m_vector && a_size == 0)
337 deallocate(m_vector);
344 m_vector = (T *)allocate(a_size*m_size);
348 m_vector = (T *)reallocate((
void *)m_vector, a_size*m_size);
353 virtual void *raw_at(
unsigned int a_index)
355 return (
void *)&m_vector[a_index];
358 T &at(
unsigned int a_index)
360 return m_vector[a_index];
371 class FE_DL_EXPORT TypeVector:
372 public BaseTypeVector,
381 m_vector.reserve(1000);
383 virtual ~TypeVector(
void)
385 #if FE_COUNTED_STORE_TRACKER 388 deregisterRegion(m_base);
393 virtual void resize(
unsigned int a_size)
395 #if FE_COUNTED_STORE_TRACKER 398 deregisterRegion(m_base);
402 m_vector.resize(a_size);
405 m_base = (
void *)&(m_vector[0]);
408 #if FE_COUNTED_STORE_TRACKER 409 registerRegion(m_base,a_size*m_size);
413 virtual void *raw_at(
unsigned int a_index)
415 return (
void *)&m_vector[a_index];
418 T &at(
unsigned int a_index)
420 return m_vector[a_index];
423 #if FE_COUNTED_STORE_TRACKER 424 const String verboseName(
void)
const {
return "TypeVector "+name(); }
434 class FE_DL_EXPORT TypeVector<bool> :
public BaseTypeVector
441 m_size =
sizeof(bool);
443 virtual ~TypeVector(
void)
447 deallocate(m_vector);
451 virtual void resize(
unsigned int a_size)
453 if(m_vector && a_size == 0)
455 deallocate(m_vector);
462 m_vector = (
bool *)allocate(a_size*m_size);
466 m_vector = (
bool *)reallocate((
void *)m_vector, a_size*m_size);
471 virtual void *raw_at(
unsigned int a_index)
473 return (
void *)&m_vector[a_index];
476 bool &at(
unsigned int a_index)
478 return m_vector[a_index];
486 template <
typename T>
487 class FE_DL_EXPORT TypeVector< std::atomic<T> > :
488 public BaseTypeVector,
489 public CastableAs< TypeVector< std::atomic<T> > >
497 m_size =
sizeof(std::atomic<T>);
502 virtual ~TypeVector(
void)
504 if(m_vector) {
delete [] m_vector; }
507 virtual void resize(
unsigned int a_size)
519 else if(a_size > m_count_used)
521 if(a_size > m_count_alloc)
523 unsigned int new_alloc = 1;
524 if(m_count_alloc > 0) { new_alloc = m_count_alloc * 2; }
525 if(m_count_alloc < a_size) { new_alloc = a_size; }
526 std::atomic<T> *from = m_vector;
527 m_vector =
new std::atomic<T>[new_alloc];
529 for(
unsigned int i = 0; i < m_count_used; i++)
531 T intermediary = from[i];
532 m_vector[i] = intermediary;
535 m_count_alloc = new_alloc;
537 for(
unsigned int i = m_count_used; i < a_size; i++)
542 m_count_used = a_size;
543 FEASSERT(m_count_used<=m_count_alloc);
546 virtual void *raw_at(
unsigned int a_index)
548 return (
void *)&m_vector[a_index];
551 std::atomic<T> &at(
unsigned int a_index)
553 FEASSERT(a_index<m_count_alloc);
554 FEASSERT(a_index<m_count_used);
555 return m_vector[a_index];
559 std::atomic<T> *m_vector;
560 unsigned int m_count_alloc;
561 unsigned int m_count_used;
576 virtual void assign(
void *lvalue,
void *rvalue);
577 virtual bool equiv(
void *a_a,
void *a_b);
582 template <
typename T>
583 class FE_DL_EXPORT Type< std::atomic<T> > :
public BaseType 588 virtual void assign(
void *lvalue,
void *rvalue);
589 virtual bool equiv(
void *a_a,
void *a_b);
613 m_typeInfo.assign<T>();
614 #if FE_COUNTED_STORE_TRACKER || FE_TYPE_STORE_NAME 615 setName(m_typeInfo.ref().name());
619 template <
typename T>
622 m_size=
sizeof(std::atomic<T>);
623 m_typeInfo.assign< std::atomic<T> >();
624 #if FE_COUNTED_STORE_TRACKER || FE_TYPE_STORE_NAME 625 setName(m_typeInfo.ref().name());
634 template <
typename T>
639 template <
typename T>
643 *(
reinterpret_cast<std::atomic<T> *
>(rvalue));
644 *(
reinterpret_cast<std::atomic<T> *
>(lvalue)) = value;
647 template <
typename T>
654 template <
typename T>
657 return (*(
reinterpret_cast<std::atomic<T> *
>(a_a)) == *(
reinterpret_cast<std::atomic<T> *
>(a_b)));
662 { *(
reinterpret_cast<T *
>(lvalue)) = *(
reinterpret_cast<T *
>(rvalue)); }
667 return (*(reinterpret_cast<T *>(a_a)) == *(reinterpret_cast<T *>(a_b)));
674 pType->registerRegion(pType,
sizeof(
Type<T>));
682 template <
typename T>
686 pType->registerRegion(pType,
sizeof(Type< std::atomic<T> >));
704 m_typeInfo.assign<
void>();
707 inline FE_UWORD BaseType::size(
void)
const 714 inline IWORD TypeInfoMemcpyIO<T>::output(std::ostream &ostrm,
void *instance,
719 ostrm.write((
char *)instance,
sizeof(T));
726 inline void TypeInfoMemcpyIO<T>::input(std::istream &ostrm,
void *instance,
729 ostrm.read((
char *)instance,
sizeof(T));
733 inline IWORD TypeInfoMemcpyIO<T>::iosize(
void)
738 inline TypeInfo::TypeInfo(
void)
740 m_pTypeInfo = &getTypeId<not_initialized>();
741 FEASSERT(m_pTypeInfo);
744 inline TypeInfo::TypeInfo(
const fe_type_info &other)
746 m_pTypeInfo = &other;
747 FEASSERT(m_pTypeInfo);
750 inline TypeInfo::TypeInfo(
const TypeInfo &other)
752 m_pTypeInfo = other.m_pTypeInfo;
753 FEASSERT(m_pTypeInfo);
760 m_pTypeInfo = other.m_pTypeInfo;
762 FEASSERT(m_pTypeInfo);
766 inline const fe_type_info &TypeInfo::ref(
void)
const 768 FEASSERT(m_pTypeInfo);
772 inline bool TypeInfo::isValid(
void)
const 774 return (
bool)(ref() != getTypeId<not_initialized>());
777 #if defined(GCC_HASCLASSVISIBILITY) || FE_RTTI_HOMEBREW == 1 778 inline bool TypeInfo::operator==(
const TypeInfo &other)
const 780 const char* n1=ref().name();
781 const char* n2=other.ref().name();
782 return n1==n2 || !strcmp(n1,n2);
785 inline bool TypeInfo::operator!=(
const TypeInfo &other)
const 787 return !(*
this==other);
790 inline bool TypeInfo::operator<(
const TypeInfo &other)
const 792 const char* n1=ref().name();
793 const char* n2=other.ref().name();
794 return strcmp(n1,n2)<0;
797 inline bool TypeInfo::operator>(
const TypeInfo &other)
const 799 const char* n1=ref().name();
800 const char* n2=other.ref().name();
801 return strcmp(n1,n2)>0;
804 inline bool TypeInfo::operator>=(
const TypeInfo &other)
const 806 return !(*
this<other);
809 inline bool TypeInfo::operator<=(
const TypeInfo &other)
const 811 return !(*
this>other);
814 inline bool TypeInfo::operator==(
const TypeInfo &other)
const 816 return ref() == other.ref();
819 inline bool TypeInfo::operator!=(
const TypeInfo &other)
const 821 return ref() != other.ref();
824 inline bool TypeInfo::operator<(
const TypeInfo &other)
const 826 return ref().before(other.ref());
829 inline bool TypeInfo::operator>(
const TypeInfo &other)
const 831 return other.ref().before(ref());
834 inline bool TypeInfo::operator>=(
const TypeInfo &other)
const 836 return !(ref().before(other.ref()));
839 inline bool TypeInfo::operator<=(
const TypeInfo &other)
const 841 return !(other.ref().before(ref()));
853 struct hash_type_info
855 FE_UWORD operator()(
const TypeInfo &t)
const 858 FE_UWORD len = strlen(t.ref().name());
859 for(FE_UWORD i = 0; i < len; i++)
860 { hash = (hash << 3) + t.ref().name()[i]; }
866 class AutoHashMap< TypeInfo, U >:
867 public HashMap< TypeInfo, U, hash_type_info, eq_type_info > {};
Class level locking for thread safety.
Definition: Safe.h:213
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
kernel
Definition: namespace.dox:3
BWORD operator!=(const DualString &s1, const DualString &s2)
Compare two DualString's (reverse logic)
Definition: DualString.h:229
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
BWORD operator==(const DualString &s1, const DualString &s2)
Compare two DualString's.
Definition: DualString.h:208
Automatically reference-counted string container.
Definition: String.h:128
Wrapper for std::vector.
Definition: Array.h:21
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192