add Callback API in ExporterProperties

pull/3280/head
Yingying Wang 2020-06-09 11:20:48 -07:00
parent ce838dfafb
commit 578a7ac502
2 changed files with 87 additions and 64 deletions

View File

@ -580,10 +580,24 @@ ExportProperties::ExportProperties(const ExportProperties &other)
: mIntProperties(other.mIntProperties)
, mFloatProperties(other.mFloatProperties)
, mStringProperties(other.mStringProperties)
, mMatrixProperties(other.mMatrixProperties) {
, mMatrixProperties(other.mMatrixProperties)
//wangyi 0608
, mCallbackProperties(other.mCallbackProperties){
// empty
}
//wangyi 0608
bool ExportProperties::SetPropertyCallback(const char *szName, std::function<void *(void *)> &f) {
return SetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, f);
}
std::function<void *(void *)> ExportProperties::GetPropertyCallback(const char *szName) const {
return GetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, 0);
}
//wangyi 0608
bool ExportProperties::HasPropertyCallback(const char *szName) const {
return HasGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName);
}
// ------------------------------------------------------------------------------------------------
// Set a configuration property
bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) {

View File

@ -47,13 +47,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_EXPORT_HPP_INC
#ifdef __GNUC__
# pragma GCC system_header
#pragma GCC system_header
#endif
#ifndef ASSIMP_BUILD_NO_EXPORT
#include "cexport.h"
#include <map>
//wangyi 0608
#include <functional>
namespace Assimp {
@ -84,7 +86,7 @@ class ASSIMP_API ExportProperties;
class ASSIMP_API Exporter {
public:
/** Function pointer type of a Export worker function */
typedef void (*fpExportFunc)(const char*, IOSystem*, const aiScene*, const ExportProperties*);
typedef void (*fpExportFunc)(const char *, IOSystem *, const aiScene *, const ExportProperties *);
/** Internal description of an Assimp export format option */
struct ExportFormatEntry {
@ -98,8 +100,7 @@ public:
unsigned int mEnforcePP;
// Constructor to fill all entries
ExportFormatEntry( const char* pId, const char* pDesc, const char* pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u)
{
ExportFormatEntry(const char *pId, const char *pDesc, const char *pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u) {
mDescription.id = pId;
mDescription.description = pDesc;
mDescription.fileExtension = pExtension;
@ -108,9 +109,8 @@ public:
}
ExportFormatEntry() :
mExportFunction()
, mEnforcePP()
{
mExportFunction(),
mEnforcePP() {
mDescription.id = NULL;
mDescription.description = NULL;
mDescription.fileExtension = NULL;
@ -142,7 +142,7 @@ public:
*
* @param pIOHandler The IO handler to be used in all file accesses
* of the Importer. */
void SetIOHandler( IOSystem* pIOHandler);
void SetIOHandler(IOSystem *pIOHandler);
// -------------------------------------------------------------------
/** Retrieves the IO handler that is currently set.
@ -151,7 +151,7 @@ public:
* handler is active as long the application doesn't supply its own
* custom IO handler via #SetIOHandler().
* @return A valid IOSystem interface, never NULL. */
IOSystem* GetIOHandler() const;
IOSystem *GetIOHandler() const;
// -------------------------------------------------------------------
/** Checks whether a default IO handler is active
@ -171,7 +171,7 @@ public:
* disable progress reporting.
* @note Progress handlers can be used to abort the loading
* at almost any time.*/
void SetProgressHandler(ProgressHandler* pHandler);
void SetProgressHandler(ProgressHandler *pHandler);
// -------------------------------------------------------------------
/** Exports the given scene to a chosen file format. Returns the exported
@ -191,10 +191,10 @@ public:
* Any IO handlers set via #SetIOHandler are ignored here.
* @note Use aiCopyScene() to get a modifiable copy of a previously
* imported scene. */
const aiExportDataBlob* ExportToBlob(const aiScene* pScene, const char* pFormatId,
unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId,
unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const char *pFormatId,
unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const std::string &pFormatId,
unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
// -------------------------------------------------------------------
/** Convenience function to export directly to a file. Use
@ -229,10 +229,10 @@ public:
* @return AI_SUCCESS if everything was fine.
* @note Use aiCopyScene() to get a modifiable copy of a previously
* imported scene.*/
aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath,
unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath,
unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
aiReturn Export(const aiScene *pScene, const char *pFormatId, const char *pPath,
unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
aiReturn Export(const aiScene *pScene, const std::string &pFormatId, const std::string &pPath,
unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr);
// -------------------------------------------------------------------
/** Returns an error description of an error that occurred in #Export
@ -244,17 +244,17 @@ public:
*
* @note The returned function remains valid until one of the
* following methods is called: #Export, #ExportToBlob, #FreeBlob */
const char* GetErrorString() const;
const char *GetErrorString() const;
// -------------------------------------------------------------------
/** Return the blob obtained from the last call to #ExportToBlob */
const aiExportDataBlob* GetBlob() const;
const aiExportDataBlob *GetBlob() const;
// -------------------------------------------------------------------
/** Orphan the blob from the last call to #ExportToBlob. This means
* the caller takes ownership and is thus responsible for calling
* the C API function #aiReleaseExportBlob to release it. */
const aiExportDataBlob* GetOrphanedBlob() const;
const aiExportDataBlob *GetOrphanedBlob() const;
// -------------------------------------------------------------------
/** Frees the current blob.
@ -264,7 +264,7 @@ public:
* automatically by the destructor. The only reason to call
* it manually would be to reclaim as much storage as possible
* without giving up the #Exporter instance yet. */
void FreeBlob( );
void FreeBlob();
// -------------------------------------------------------------------
/** Returns the number of export file formats available in the current
@ -290,7 +290,7 @@ public:
* for. Valid range is 0 to #Exporter::GetExportFormatCount
* @return A description of that specific export format.
* NULL if pIndex is out of range. */
const aiExportFormatDesc* GetExportFormatDescription( size_t pIndex ) const;
const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const;
// -------------------------------------------------------------------
/** Register a custom exporter. Custom export formats are limited to
@ -303,7 +303,7 @@ public:
* registered. A common cause that would prevent an exporter
* from being registered is that its format id is already
* occupied by another format. */
aiReturn RegisterExporter(const ExportFormatEntry& desc);
aiReturn RegisterExporter(const ExportFormatEntry &desc);
// -------------------------------------------------------------------
/** Remove an export format previously registered with #RegisterExporter
@ -314,11 +314,11 @@ public:
* 'id' field of #aiExportFormatDesc.
* @note Calling this method on a format description not yet registered
* has no effect.*/
void UnregisterExporter(const char* id);
void UnregisterExporter(const char *id);
protected:
// Just because we don't want you to know how we're hacking around.
ExporterPimpl* pimpl;
ExporterPimpl *pimpl;
};
class ASSIMP_API ExportProperties {
@ -332,6 +332,8 @@ public:
typedef std::map<KeyType, ai_real> FloatPropertyMap;
typedef std::map<KeyType, std::string> StringPropertyMap;
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
//wangyi 0608
typedef std::map<KeyType, std::function<void *(void *)>> CallbackPropertyMap;
public:
/** Standard constructor
@ -345,7 +347,7 @@ public:
* This copies the configuration properties of another ExportProperties.
* @see ExportProperties(const ExportProperties& other)
*/
ExportProperties(const ExportProperties& other);
ExportProperties(const ExportProperties &other);
// -------------------------------------------------------------------
/** Set an integer configuration property.
@ -360,7 +362,7 @@ public:
* floating-point property has no effect - the loader will call
* GetPropertyFloat() to read the property, but it won't be there.
*/
bool SetPropertyInteger(const char* szName, int iValue);
bool SetPropertyInteger(const char *szName, int iValue);
// -------------------------------------------------------------------
/** Set a boolean configuration property. Boolean properties
@ -369,27 +371,30 @@ public:
* #GetPropertyBool and vice versa.
* @see SetPropertyInteger()
*/
bool SetPropertyBool(const char* szName, bool value) {
return SetPropertyInteger(szName,value);
bool SetPropertyBool(const char *szName, bool value) {
return SetPropertyInteger(szName, value);
}
// -------------------------------------------------------------------
/** Set a floating-point configuration property.
* @see SetPropertyInteger()
*/
bool SetPropertyFloat(const char* szName, ai_real fValue);
bool SetPropertyFloat(const char *szName, ai_real fValue);
// -------------------------------------------------------------------
/** Set a string configuration property.
* @see SetPropertyInteger()
*/
bool SetPropertyString(const char* szName, const std::string& sValue);
bool SetPropertyString(const char *szName, const std::string &sValue);
// -------------------------------------------------------------------
/** Set a matrix configuration property.
* @see SetPropertyInteger()
*/
bool SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue);
bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue);
//wangyi 0608
bool SetPropertyCallback(const char *szName, std::function<void *(void *)> &f);
// -------------------------------------------------------------------
/** Get a configuration property.
@ -404,8 +409,8 @@ public:
* floating-point property has no effect - the loader will call
* GetPropertyFloat() to read the property, but it won't be there.
*/
int GetPropertyInteger(const char* szName,
int iErrorReturn = 0xffffffff) const;
int GetPropertyInteger(const char *szName,
int iErrorReturn = 0xffffffff) const;
// -------------------------------------------------------------------
/** Get a boolean configuration property. Boolean properties
@ -414,16 +419,16 @@ public:
* #GetPropertyBool and vice versa.
* @see GetPropertyInteger()
*/
bool GetPropertyBool(const char* szName, bool bErrorReturn = false) const {
return GetPropertyInteger(szName,bErrorReturn)!=0;
bool GetPropertyBool(const char *szName, bool bErrorReturn = false) const {
return GetPropertyInteger(szName, bErrorReturn) != 0;
}
// -------------------------------------------------------------------
/** Get a floating-point configuration property
* @see GetPropertyInteger()
*/
ai_real GetPropertyFloat(const char* szName,
ai_real fErrorReturn = 10e10f) const;
ai_real GetPropertyFloat(const char *szName,
ai_real fErrorReturn = 10e10f) const;
// -------------------------------------------------------------------
/** Get a string configuration property
@ -431,8 +436,8 @@ public:
* The return value remains valid until the property is modified.
* @see GetPropertyInteger()
*/
const std::string GetPropertyString(const char* szName,
const std::string& sErrorReturn = "") const;
const std::string GetPropertyString(const char *szName,
const std::string &sErrorReturn = "") const;
// -------------------------------------------------------------------
/** Get a matrix configuration property
@ -440,37 +445,42 @@ public:
* The return value remains valid until the property is modified.
* @see GetPropertyInteger()
*/
const aiMatrix4x4 GetPropertyMatrix(const char* szName,
const aiMatrix4x4& sErrorReturn = aiMatrix4x4()) const;
const aiMatrix4x4 GetPropertyMatrix(const char *szName,
const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const;
// -------------------------------------------------------------------
/** Determine a integer configuration property has been set.
//wangyi 0608
std::function<void *(void *)> GetPropertyCallback(const char* szName) const;
// -------------------------------------------------------------------
/** Determine a integer configuration property has been set.
* @see HasPropertyInteger()
*/
bool HasPropertyInteger(const char* szName) const;
bool HasPropertyInteger(const char *szName) const;
/** Determine a boolean configuration property has been set.
* @see HasPropertyBool()
*/
bool HasPropertyBool(const char* szName) const;
bool HasPropertyBool(const char *szName) const;
/** Determine a boolean configuration property has been set.
* @see HasPropertyFloat()
*/
bool HasPropertyFloat(const char* szName) const;
bool HasPropertyFloat(const char *szName) const;
/** Determine a String configuration property has been set.
* @see HasPropertyString()
*/
bool HasPropertyString(const char* szName) const;
bool HasPropertyString(const char *szName) const;
/** Determine a Matrix configuration property has been set.
* @see HasPropertyMatrix()
*/
bool HasPropertyMatrix(const char* szName) const;
bool HasPropertyMatrix(const char *szName) const;
//wangyi 0608
bool HasPropertyCallback(const char *szName) const;
protected:
/** List of integer properties */
IntPropertyMap mIntProperties;
@ -482,23 +492,22 @@ protected:
/** List of Matrix properties */
MatrixPropertyMap mMatrixProperties;
//wangyi 0608
CallbackPropertyMap mCallbackProperties;
};
// ----------------------------------------------------------------------------------
inline
const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const std::string& pFormatId,
unsigned int pPreprocessing, const ExportProperties* pProperties)
{
return ExportToBlob(pScene,pFormatId.c_str(),pPreprocessing, pProperties);
inline const aiExportDataBlob *Exporter::ExportToBlob(const aiScene *pScene, const std::string &pFormatId,
unsigned int pPreprocessing, const ExportProperties *pProperties) {
return ExportToBlob(pScene, pFormatId.c_str(), pPreprocessing, pProperties);
}
// ----------------------------------------------------------------------------------
inline
aiReturn Exporter :: Export( const aiScene* pScene, const std::string& pFormatId,
const std::string& pPath, unsigned int pPreprocessing,
const ExportProperties* pProperties)
{
return Export(pScene,pFormatId.c_str(),pPath.c_str(),pPreprocessing, pProperties);
inline aiReturn Exporter ::Export(const aiScene *pScene, const std::string &pFormatId,
const std::string &pPath, unsigned int pPreprocessing,
const ExportProperties *pProperties) {
return Export(pScene, pFormatId.c_str(), pPath.c_str(), pPreprocessing, pProperties);
}
} // namespace Assimp