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) : mIntProperties(other.mIntProperties)
, mFloatProperties(other.mFloatProperties) , mFloatProperties(other.mFloatProperties)
, mStringProperties(other.mStringProperties) , mStringProperties(other.mStringProperties)
, mMatrixProperties(other.mMatrixProperties) { , mMatrixProperties(other.mMatrixProperties)
//wangyi 0608
, mCallbackProperties(other.mCallbackProperties){
// empty // 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 // Set a configuration property
bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) { bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) {

View File

@ -54,6 +54,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cexport.h" #include "cexport.h"
#include <map> #include <map>
//wangyi 0608
#include <functional>
namespace Assimp { namespace Assimp {
@ -98,8 +100,7 @@ public:
unsigned int mEnforcePP; unsigned int mEnforcePP;
// Constructor to fill all entries // 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.id = pId;
mDescription.description = pDesc; mDescription.description = pDesc;
mDescription.fileExtension = pExtension; mDescription.fileExtension = pExtension;
@ -108,9 +109,8 @@ public:
} }
ExportFormatEntry() : ExportFormatEntry() :
mExportFunction() mExportFunction(),
, mEnforcePP() mEnforcePP() {
{
mDescription.id = NULL; mDescription.id = NULL;
mDescription.description = NULL; mDescription.description = NULL;
mDescription.fileExtension = NULL; mDescription.fileExtension = NULL;
@ -332,6 +332,8 @@ public:
typedef std::map<KeyType, ai_real> FloatPropertyMap; typedef std::map<KeyType, ai_real> FloatPropertyMap;
typedef std::map<KeyType, std::string> StringPropertyMap; typedef std::map<KeyType, std::string> StringPropertyMap;
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap; typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
//wangyi 0608
typedef std::map<KeyType, std::function<void *(void *)>> CallbackPropertyMap;
public: public:
/** Standard constructor /** Standard constructor
@ -391,6 +393,9 @@ public:
*/ */
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. /** Get a configuration property.
* @param szName Name of the property. All supported properties * @param szName Name of the property. All supported properties
@ -443,6 +448,9 @@ public:
const aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 GetPropertyMatrix(const char *szName,
const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const;
//wangyi 0608
std::function<void *(void *)> GetPropertyCallback(const char* szName) const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Determine a integer configuration property has been set. /** Determine a integer configuration property has been set.
* @see HasPropertyInteger() * @see HasPropertyInteger()
@ -469,8 +477,10 @@ public:
*/ */
bool HasPropertyMatrix(const char *szName) const; bool HasPropertyMatrix(const char *szName) const;
protected: //wangyi 0608
bool HasPropertyCallback(const char *szName) const;
protected:
/** List of integer properties */ /** List of integer properties */
IntPropertyMap mIntProperties; IntPropertyMap mIntProperties;
@ -482,22 +492,21 @@ protected:
/** List of Matrix properties */ /** List of Matrix properties */
MatrixPropertyMap mMatrixProperties; MatrixPropertyMap mMatrixProperties;
//wangyi 0608
CallbackPropertyMap mCallbackProperties;
}; };
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
inline inline const aiExportDataBlob *Exporter::ExportToBlob(const aiScene *pScene, const std::string &pFormatId,
const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const std::string& pFormatId, unsigned int pPreprocessing, const ExportProperties *pProperties) {
unsigned int pPreprocessing, const ExportProperties* pProperties)
{
return ExportToBlob(pScene, pFormatId.c_str(), pPreprocessing, pProperties); return ExportToBlob(pScene, pFormatId.c_str(), pPreprocessing, pProperties);
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
inline inline aiReturn Exporter ::Export(const aiScene *pScene, const std::string &pFormatId,
aiReturn Exporter :: Export( const aiScene* pScene, const std::string& pFormatId,
const std::string &pPath, unsigned int pPreprocessing, const std::string &pPath, unsigned int pPreprocessing,
const ExportProperties* pProperties) const ExportProperties *pProperties) {
{
return Export(pScene, pFormatId.c_str(), pPath.c_str(), pPreprocessing, pProperties); return Export(pScene, pFormatId.c_str(), pPath.c_str(), pPreprocessing, pProperties);
} }