Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualHeuristics

Posted 12 March 2013 - 06:19 AM

Ok, I have now dug deep into gccs type_traits and tr1/type_traits files and this looks like it might work after some simple testing (will need to do more testing, will report back later). Only problem with this one appears to be that I cannot find a c++11 has_trivial_copy function, it appears to be unimplemented, but it does exist in the tr1 (pre c++11 file)

 

#include <type_traits>
#include <tr1/type_traits>
template<typename T>
void automaticallyRegisterObjectTypeAsValue(asIScriptEngine *engine, std::string name) {
        bool hasConstructor =  std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
        bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
        bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
        bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::tr1::has_trivial_copy<T>::value;


       asDWORD flags = asOBJ_VALUE | asOBJ_APP_CLASS;
       if(hasConstructor) flags = flags | asOBJ_APP_CLASS_CONSTRUCTOR;
       if(hasDestructor) flags = flags | asOBJ_APP_CLASS_DESTRUCTOR;
       if(hasAssignmentOperator) flags = flags | asOBJ_APP_CLASS_ASSIGNMENT;
       if(hasCopyConstructor) flags = flags | asOBJ_APP_CLASS_COPY_CONSTRUCTOR;

       int r = engine->RegisterObjectType(name.c_str(), sizeof(T), flags ); assert( r >= 0 );
}

#2Heuristics

Posted 12 March 2013 - 06:17 AM

Ok, I have now dug deep into gccs type_traits and tr1/type_traits files and this looks like it might work after some simple testing (will need to do more testing, will report back later).

 

#include <type_traits>
#include <tr1/type_traits>
template<typename T>
void automaticallyRegisterObjectTypeAsValue(asIScriptEngine *engine, std::string name) {
        bool hasConstructor =  std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
        bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
        bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
        bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::tr1::has_trivial_copy<T>::value;


       asDWORD flags = asOBJ_VALUE | asOBJ_APP_CLASS;
       if(hasConstructor) flags = flags | asOBJ_APP_CLASS_CONSTRUCTOR;
       if(hasDestructor) flags = flags | asOBJ_APP_CLASS_DESTRUCTOR;
       if(hasAssignmentOperator) flags = flags | asOBJ_APP_CLASS_ASSIGNMENT;
       if(hasCopyConstructor) flags = flags | asOBJ_APP_CLASS_COPY_CONSTRUCTOR;

       int r = engine->RegisterObjectType(name.c_str(), sizeof(T), flags ); assert( r >= 0 );
}

#1Heuristics

Posted 12 March 2013 - 06:17 AM

Ok, I have now fug deep into gccs type_traits and tr1/type_traits files and this looks like it might work after some simple testing (will need to do more testing, will report back later).

 

#include <type_traits>
#include <tr1/type_traits>
template<typename T>
void automaticallyRegisterObjectTypeAsValue(asIScriptEngine *engine, std::string name) {
        bool hasConstructor =  std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
        bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
        bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
        bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::tr1::has_trivial_copy<T>::value;


       asDWORD flags = asOBJ_VALUE | asOBJ_APP_CLASS;
       if(hasConstructor) flags = flags | asOBJ_APP_CLASS_CONSTRUCTOR;
       if(hasDestructor) flags = flags | asOBJ_APP_CLASS_DESTRUCTOR;
       if(hasAssignmentOperator) flags = flags | asOBJ_APP_CLASS_ASSIGNMENT;
       if(hasCopyConstructor) flags = flags | asOBJ_APP_CLASS_COPY_CONSTRUCTOR;

       int r = engine->RegisterObjectType(name.c_str(), sizeof(T), flags ); assert( r >= 0 );
}

PARTNERS