mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
common: Introduce class type identifier apis.
This identifier is useful when user identify the instance type in runtime. ThorVG basically don't prefer to dynamic_cast() nor typeid(), it compiles with -fno-rtti option for the optimial size. Here is an example for the simple usage. if (paint->identifier() == Shape::identifier()) auto shape = static_cast<Shape*>(paint); @Issue: https://github.com/Samsung/thorvg/issues/693
This commit is contained in:
parent
8a7ec66cb2
commit
78d85d714a
6 changed files with 109 additions and 2 deletions
77
inc/thorvg.h
77
inc/thorvg.h
|
@ -339,6 +339,17 @@ public:
|
|||
*/
|
||||
CompositeMethod composite(const Paint** target) const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the unique id value of the paint instance.
|
||||
*
|
||||
* This method can be called for checking the current concrete instance type.
|
||||
*
|
||||
* @return The type id of the Paint instance.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
uint32_t identifier() const { return _id; }
|
||||
|
||||
_TVG_DECLARE_ACCESSOR();
|
||||
_TVG_DECALRE_IDENTIFIER();
|
||||
_TVG_DECLARE_PRIVATE(Paint);
|
||||
|
@ -441,6 +452,17 @@ public:
|
|||
*/
|
||||
Fill* duplicate() const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the unique id value of the Fill instance.
|
||||
*
|
||||
* This method can be called for checking the current concrete instance type.
|
||||
*
|
||||
* @return The type id of the Fill instance.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
uint32_t identifier() const { return _id; }
|
||||
|
||||
_TVG_DECALRE_IDENTIFIER();
|
||||
_TVG_DECLARE_PRIVATE(Fill);
|
||||
};
|
||||
|
@ -598,6 +620,17 @@ public:
|
|||
*/
|
||||
static std::unique_ptr<LinearGradient> gen() noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the unique id value of this class.
|
||||
*
|
||||
* This method can be referred for identifying the LinearGradient class type.
|
||||
*
|
||||
* @return The type id of the LinearGradient class.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
static uint32_t identifier() noexcept;
|
||||
|
||||
_TVG_DECLARE_PRIVATE(LinearGradient);
|
||||
};
|
||||
|
||||
|
@ -646,6 +679,17 @@ public:
|
|||
*/
|
||||
static std::unique_ptr<RadialGradient> gen() noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the unique id value of this class.
|
||||
*
|
||||
* This method can be referred for identifying the RadialGradient class type.
|
||||
*
|
||||
* @return The type id of the RadialGradient class.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
static uint32_t identifier() noexcept;
|
||||
|
||||
_TVG_DECLARE_PRIVATE(RadialGradient);
|
||||
};
|
||||
|
||||
|
@ -1020,6 +1064,17 @@ public:
|
|||
*/
|
||||
static std::unique_ptr<Shape> gen() noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the unique id value of this class.
|
||||
*
|
||||
* This method can be referred for identifying the Shape class type.
|
||||
*
|
||||
* @return The type id of the Shape class.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
static uint32_t identifier() noexcept;
|
||||
|
||||
_TVG_DECLARE_PRIVATE(Shape);
|
||||
};
|
||||
|
||||
|
@ -1146,6 +1201,17 @@ public:
|
|||
*/
|
||||
static std::unique_ptr<Picture> gen() noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the unique id value of this class.
|
||||
*
|
||||
* This method can be referred for identifying the Picture class type.
|
||||
*
|
||||
* @return The type id of the Picture class.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
static uint32_t identifier() noexcept;
|
||||
|
||||
_TVG_DECLARE_PRIVATE(Picture);
|
||||
};
|
||||
|
||||
|
@ -1215,6 +1281,17 @@ public:
|
|||
*/
|
||||
static std::unique_ptr<Scene> gen() noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the unique id value of this class.
|
||||
*
|
||||
* This method can be referred for identifying the Scene class type.
|
||||
*
|
||||
* @return The type id of the Scene class.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
static uint32_t identifier() noexcept;
|
||||
|
||||
_TVG_DECLARE_PRIVATE(Scene);
|
||||
};
|
||||
|
||||
|
|
|
@ -91,3 +91,9 @@ unique_ptr<LinearGradient> LinearGradient::gen() noexcept
|
|||
{
|
||||
return unique_ptr<LinearGradient>(new LinearGradient);
|
||||
}
|
||||
|
||||
|
||||
uint32_t LinearGradient::identifier() noexcept
|
||||
{
|
||||
return TVG_CLASS_ID_LINEAR;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,12 @@ unique_ptr<Picture> Picture::gen() noexcept
|
|||
}
|
||||
|
||||
|
||||
uint32_t Picture::identifier() noexcept
|
||||
{
|
||||
return TVG_CLASS_ID_PICTURE;
|
||||
}
|
||||
|
||||
|
||||
Result Picture::load(const std::string& path) noexcept
|
||||
{
|
||||
if (path.empty()) return Result::InvalidArguments;
|
||||
|
|
|
@ -89,3 +89,9 @@ unique_ptr<RadialGradient> RadialGradient::gen() noexcept
|
|||
{
|
||||
return unique_ptr<RadialGradient>(new RadialGradient);
|
||||
}
|
||||
|
||||
|
||||
uint32_t RadialGradient::identifier() noexcept
|
||||
{
|
||||
return TVG_CLASS_ID_RADIAL;
|
||||
}
|
|
@ -44,6 +44,12 @@ unique_ptr<Scene> Scene::gen() noexcept
|
|||
}
|
||||
|
||||
|
||||
uint32_t Scene::identifier() noexcept
|
||||
{
|
||||
return TVG_CLASS_ID_SCENE;
|
||||
}
|
||||
|
||||
|
||||
Result Scene::push(unique_ptr<Paint> paint) noexcept
|
||||
{
|
||||
auto p = paint.release();
|
||||
|
|
|
@ -55,6 +55,12 @@ unique_ptr<Shape> Shape::gen() noexcept
|
|||
}
|
||||
|
||||
|
||||
uint32_t Shape::identifier() noexcept
|
||||
{
|
||||
return TVG_CLASS_ID_SHAPE;
|
||||
}
|
||||
|
||||
|
||||
Result Shape::reset() noexcept
|
||||
{
|
||||
pImpl->path.reset();
|
||||
|
|
Loading…
Add table
Reference in a new issue