APEX Framework: NvParameterizedTraits.h Source File

NVIDIA APEX

NvParameterizedTraits.h
Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved.
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 * /*className*/, uint32_t /*from*/, uint32_t /*to*/, Conversion & /*conv*/) {}
00203 
00207     virtual ::NvParameterized::Conversion *removeConversion(const char * /*className*/, uint32_t /*from*/, uint32_t /*to*/) { 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 * /*buf*/, ::NvParameterized::Interface * /*obj*/) {}
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 * /*msg*/) 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 * /*filename*/, int /*line*/)
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 } // namespace NvParameterized
00372 
00373 #endif // NV_PARAMETERIZED_TRAITS_H

Generated on Fri Dec 15 2017 13:58:35
Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.