NvParameterizedTraits.h
Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 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 Sat Dec 1 2018 15:52:05

Copyright © 2012-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.