Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef NV_PARAMETERIZED_TRAITS_H
00029 #define NV_PARAMETERIZED_TRAITS_H
00030
00036 #include <string.h>
00037 #include "foundation/PxAssert.h"
00038
00039 namespace NvParameterized
00040 {
00041
00042 PX_PUSH_PACK_DEFAULT
00043
00044 class Traits;
00045 class Interface;
00046
00050 class Factory
00051 {
00052 public:
00053
00057 virtual ::NvParameterized::Interface *create( Traits *paramTraits ) = 0;
00058
00062 virtual ::NvParameterized::Interface *finish( Traits *paramTraits, void *obj, void *buf, int32_t *refCount ) = 0;
00063
00067 virtual const char * getClassName() = 0;
00068
00072 virtual uint32_t getVersion() = 0;
00073
00077 virtual uint32_t getAlignment() = 0;
00078
00082 virtual const uint32_t * getChecksum( uint32_t &bits ) = 0;
00083
00087 virtual ~Factory() {}
00088
00092 virtual void freeParameterDefinitionTable(NvParameterized::Traits* traits) = 0;
00093 };
00094
00098 class Conversion
00099 {
00100 public:
00101 virtual ~Conversion() {}
00102
00110 virtual bool operator()(::NvParameterized::Interface &legacyObj, ::NvParameterized::Interface &obj) = 0;
00111
00115 virtual void release() = 0;
00116 };
00117
00124 class Traits
00125 {
00126 public:
00127 virtual ~Traits() {}
00128
00132 virtual void registerFactory( ::NvParameterized::Factory & factory ) = 0;
00133
00138 virtual ::NvParameterized::Factory *removeFactory( const char * className ) = 0;
00139
00144 virtual ::NvParameterized::Factory *removeFactory( const char * className, uint32_t version ) = 0;
00145
00149 virtual bool doesFactoryExist(const char* className) = 0;
00150
00154 virtual bool doesFactoryExist(const char* className, uint32_t version) = 0;
00155
00163 virtual ::NvParameterized::Interface * createNvParameterized( const char * name ) = 0;
00164
00173 virtual ::NvParameterized::Interface * createNvParameterized( const char * name, uint32_t ver ) = 0;
00174
00180 virtual ::NvParameterized::Interface * finishNvParameterized( const char * name, void *obj, void *buf, int32_t *refCount ) = 0;
00181
00187 virtual ::NvParameterized::Interface * finishNvParameterized( const char * name, uint32_t ver, void *obj, void *buf, int32_t *refCount ) = 0;
00188
00192 virtual uint32_t getCurrentVersion(const char *className) const = 0;
00193
00197 virtual uint32_t getAlignment(const char *className, uint32_t classVersion) const = 0;
00198
00202 virtual void registerConversion(const char * , uint32_t , uint32_t , Conversion & ) {}
00203
00207 virtual ::NvParameterized::Conversion *removeConversion(const char * , uint32_t , uint32_t ) { return 0; }
00208
00216 virtual bool updateLegacyNvParameterized(::NvParameterized::Interface &legacyObj, ::NvParameterized::Interface &obj)
00217 {
00218 PX_UNUSED(&legacyObj);
00219 PX_UNUSED(&obj);
00220
00221 return false;
00222 }
00223
00235 virtual bool getNvParameterizedNames( const char ** names, uint32_t &outCount, uint32_t inCount) const = 0;
00236
00249 virtual bool getNvParameterizedVersions(const char* className, uint32_t* versions, uint32_t &outCount, uint32_t inCount) const = 0;
00250
00254 virtual int32_t incRefCount(int32_t *refCount) = 0;
00255
00259 virtual int32_t decRefCount(int32_t *refCount) = 0;
00260
00264 virtual void onInplaceObjectDestroyed(void * , ::NvParameterized::Interface * ) {}
00265
00269 virtual void onAllInplaceObjectsDestroyed(void *buf) { free(buf); }
00270
00274 virtual void *alloc(uint32_t nbytes) = 0;
00275
00279 virtual void *alloc(uint32_t nbytes, uint32_t align) = 0;
00280
00284 virtual void free(void *buf) = 0;
00285
00289 virtual char *strdup(const char *str)
00290 {
00291 if( !str )
00292 return NULL;
00293
00294 uint32_t strLen = (uint32_t)strlen(str) + 1;
00295 char *retStr = (char *)this->alloc(strLen, 1);
00296
00297 PX_ASSERT( retStr );
00298
00299 if( NULL != retStr )
00300 #if PX_WINDOWS_FAMILY || PX_XBOXONE
00301 strcpy_s( retStr, strLen, str );
00302 #else
00303 strncpy(retStr, str, strLen);
00304 #endif
00305 return retStr;
00306 }
00307
00311 virtual void strfree(char *str)
00312 {
00313 if( NULL != str )
00314 this->free( str );
00315 }
00316
00320 virtual void traitsWarn(const char * ) const {}
00321
00325 virtual void release(void) = 0;
00326
00330 class Allocator
00331 {
00332 ::NvParameterized::Traits *mTraits;
00333
00334 public:
00335
00339 Allocator(Traits *traits): mTraits(traits) {}
00340
00344 void *allocate(size_t size)
00345 {
00346 return allocate(size, __FILE__, __LINE__);
00347 }
00348
00352 void *allocate(size_t size, const char * , int )
00353 {
00354 PX_ASSERT( static_cast<uint32_t>(size) == size );
00355 return mTraits->alloc(static_cast<uint32_t>(size));
00356 }
00357
00361 void deallocate(void *ptr)
00362 {
00363 return mTraits->free(ptr);
00364 }
00365 };
00366 };
00367
00368
00369 PX_POP_PACK
00370
00371 }
00372
00373 #endif // NV_PARAMETERIZED_TRAITS_H