Cosmetic fixes in dali-scene-loader. 77/250177/4
authorGyörgy Straub <g.straub@partner.samsung.com>
Mon, 21 Dec 2020 17:05:03 +0000 (17:05 +0000)
committerGyorgy Straub <g.straub@partner.samsung.com>
Wed, 23 Dec 2020 11:40:59 +0000 (11:40 +0000)
- implementation of (public-api) structors moved out of headers;
- default structors replaced with 'default' keyword where possible;
- disallowed construction of 'namespace' classes;
- whitespace;
- etc.

Change-Id: I9c2e5ef3d8620cad9f7077cd2e8bacd352ea37ee
Signed-off-by: György Straub <g.straub@partner.samsung.com>
13 files changed:
dali-scene-loader/public-api/animation-definition.cpp
dali-scene-loader/public-api/blend-shape-details.h
dali-scene-loader/public-api/camera-parameters.h
dali-scene-loader/public-api/dli-loader.cpp
dali-scene-loader/public-api/material-definition.cpp
dali-scene-loader/public-api/material-definition.h
dali-scene-loader/public-api/mesh-definition.cpp
dali-scene-loader/public-api/mesh-definition.h
dali-scene-loader/public-api/node-definition.h
dali-scene-loader/public-api/scene-definition.cpp
dali-scene-loader/public-api/skinning-details.h
dali-scene-loader/public-api/utils.cpp
dali-scene-loader/public-api/utils.h

index b41b8d5..ee2b519 100644 (file)
@@ -32,11 +32,10 @@ Animation::EndAction AnimationDefinition::StopForModification(Animation& anim)
   return endAction;
 }
 
-AnimationDefinition::AnimationDefinition()
-{}
+AnimationDefinition::AnimationDefinition() = default;
 
 AnimationDefinition::AnimationDefinition(AnimationDefinition&& other)
-:  mName(std::move(other.mName)),
+: mName(std::move(other.mName)),
   mDuration(other.mDuration),
   mLoopCount(other.mLoopCount),
   mDisconnectAction(other.mDisconnectAction),
index 7ea6d3f..67283a8 100644 (file)
@@ -68,6 +68,8 @@ struct DALI_SCENE_LOADER_API BlendShapes
    *  on the given @a shader and @a actor.
    */
   static void ConfigureProperties(const std::pair<MeshDefinition, MeshGeometry>& mesh, Shader shader, Actor actor);
+
+  BlendShapes() = delete;
 };
 
 }
index 20b3ee3..044c7f4 100644 (file)
@@ -35,23 +35,12 @@ namespace SceneLoader
 
 struct DALI_SCENE_LOADER_API CameraParameters
 {
-  CameraParameters()
-  : matrix(Matrix::IDENTITY),
-    orthographicSize(-1.f, 1.f, 1.f, -1.f),
-    yFov(60.f),
-    zNear(0.1f),
-    zFar(1000.f),
-    isPerspective(true)
-  {}
-
-  ~CameraParameters() = default;
-
-  Matrix matrix;
-  Vector4 orthographicSize;
-  float yFov;
-  float zNear;
-  float zFar;
-  bool isPerspective;
+  Matrix matrix = Matrix::IDENTITY;
+  Vector4 orthographicSize = Vector4{ -1.f, 1.f, 1.f, -1.f };
+  float yFov = 60.f;
+  float zNear = 0.1f;
+  float zFar = 1000.f;
+  bool isPerspective = true;
 
   /**
    * @return The view-projection matrix of the camera.
index 06268eb..11dc036 100644 (file)
@@ -159,9 +159,9 @@ void ReadArcField(const TreeNode* eArc, ArcNode& arc)
   ReadFloat(eArc->GetChild("endAngle"), arc.mEndAngleDegrees);
 }
 
-const TreeNode *Tidx(const TreeNode *node, int index)
+const TreeNode *GetNthChild(const TreeNode *node, uint32_t index)
 {
-  int i = 0;
+  uint32_t i = 0;
   for (TreeNode::ConstIterator it = (*node).CBegin(); it != (*node).CEnd(); ++it, ++i)
   {
     if (i == index)
@@ -463,8 +463,8 @@ void DliLoader::Impl::ParseScene(LoadParams& params)
 void DliLoader::Impl::ParseSceneInternal(Index iScene, const Toolkit::TreeNode* tnScenes,
   const Toolkit::TreeNode* tnNodes, LoadParams& params)
 {
-  auto getSceneRootIdx = [&](Index iScene) {
-    auto tn = Tidx(tnScenes, iScene);  // now a "scene" object
+  auto getSceneRootIdx = [tnScenes, tnNodes](Index iScene) {
+    auto tn = GetNthChild(tnScenes, iScene);  // now a "scene" object
     if (!tn)
     {
       ExceptionFlinger(ASSERT_LOCATION) << iScene << " is out of bounds access into " << SCENES << ".";
@@ -483,7 +483,7 @@ void DliLoader::Impl::ParseSceneInternal(Index iScene, const Toolkit::TreeNode*
         " must define a node id.";
     }
 
-    tn = Tidx(tn, 0);  // now the first element of the array
+    tn = GetNthChild(tn, 0);  // now the first element of the array
     Index iRootNode;
     if (!ReadIndex(tn, iRootNode))
     {
@@ -496,7 +496,7 @@ void DliLoader::Impl::ParseSceneInternal(Index iScene, const Toolkit::TreeNode*
       ExceptionFlinger(ASSERT_LOCATION) << "Root node index << " << iRootNode << " of scene " << iScene << " is out of bounds.";
     }
 
-    tn = Tidx(tnNodes, iRootNode);  // now a "node" object
+    tn = GetNthChild(tnNodes, iRootNode);  // now a "node" object
     if (tn->GetType() != TreeNode::OBJECT)
     {
       ExceptionFlinger(ASSERT_LOCATION) << "Root node of scene " << iScene << " is of invalid JSON type; object required";
@@ -1095,7 +1095,7 @@ void DliLoader::Impl::ParseNodesInternal(const TreeNode* const nodes, Index inde
   std::vector<IndexProperty> resourceIds;
   resourceIds.reserve(4);
 
-  if (auto node = Tidx(nodes, index))
+  if (auto node = GetNthChild(nodes, index))
   {
     NodeDefinition nodeDef;
     nodeDef.mParentIdx = inOutParentStack.empty() ? INVALID_INDEX : inOutParentStack.back();
index ca1244b..952a824 100644 (file)
@@ -100,6 +100,11 @@ Sampler SamplerFlags::MakeSampler(Type flags)
   return sampler;
 }
 
+TextureDefinition::TextureDefinition(const std::string& imageUri, SamplerFlags::Type samplerFlags)
+: mImageUri(imageUri),
+  mSamplerFlags(samplerFlags)
+{}
+
 MaterialDefinition::RawData
   MaterialDefinition::LoadRaw(const std::string& imagesPath) const
 {
index 619e849..d360c88 100644 (file)
@@ -116,10 +116,7 @@ struct DALI_SCENE_LOADER_API TextureDefinition
   std::string mImageUri;
   SamplerFlags::Type mSamplerFlags;
 
-  TextureDefinition(const std::string& imageUri = "", SamplerFlags::Type samplerFlags = SamplerFlags::DEFAULT)
-  :  mImageUri(imageUri),
-    mSamplerFlags(samplerFlags)
-  {}
+  TextureDefinition(const std::string& imageUri = "", SamplerFlags::Type samplerFlags = SamplerFlags::DEFAULT);
 };
 
 /**
index 9823295..2cea908 100644 (file)
@@ -64,7 +64,7 @@ private:
 };
 
 
-const std::string QUAD_STRING("quad");
+const std::string QUAD("quad");
 
 ///@brief Reads a blob from the given stream @a source into @a target, which must have
 /// at least @a descriptor.length bytes.
@@ -290,10 +290,10 @@ void CalculateTextureSize(uint32_t totalTextureSize, uint32_t& textureWidth, uin
 {
   DALI_ASSERT_DEBUG(0u != totalTextureSize && "totalTextureSize is zero.")
 
-    // Calculate the dimensions of the texture.
-    // The total size of the texture is the length of the blend shapes blob.
+  // Calculate the dimensions of the texture.
+  // The total size of the texture is the length of the blend shapes blob.
 
-    textureWidth = 0u;
+  textureWidth = 0u;
   textureHeight = 0u;
 
   if (0u == totalTextureSize)
@@ -443,14 +443,14 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, std::ifstream& binFile,
 }
 
 MeshDefinition::SparseBlob::SparseBlob(const Blob& indices, const Blob& values, uint32_t count)
-:  mIndices{indices},
+: mIndices{indices},
   mValues{values},
   mCount{count}
 {}
 
 MeshDefinition::Accessor::Accessor(const MeshDefinition::Blob& blob,
   const MeshDefinition::SparseBlob& sparse)
-:  mBlob{blob},
+: mBlob{blob},
   mSparse{(sparse.mIndices.IsDefined() && sparse.mValues.IsDefined()) ? new SparseBlob{sparse} : nullptr}
 {}
 
@@ -489,6 +489,15 @@ void MeshDefinition::Blob::ApplyMinMax(const std::vector<float>& min, const std:
   }
 }
 
+MeshDefinition::Blob::Blob(uint32_t offset, uint32_t length, uint16_t stride, uint16_t elementSizeHint, const std::vector<float>& min, const std::vector<float>& max)
+: mOffset(offset),
+  mLength(length),
+  mStride(stride),
+  mElementSizeHint(elementSizeHint),
+  mMin(min),
+  mMax(max)
+{}
+
 uint32_t MeshDefinition::Blob::GetBufferSize() const
 {
   return IsConsecutive() ? mLength : (mLength * mElementSizeHint / mStride);
@@ -511,7 +520,7 @@ void MeshDefinition::RawData::Attrib::AttachBuffer(Geometry& g) const
 
 bool MeshDefinition::IsQuad() const
 {
-  return CaseInsensitiveStringCompare("quad", mUri);
+  return CaseInsensitiveStringCompare(QUAD, mUri);
 }
 
 bool MeshDefinition::IsSkinned() const
index 6a1eaa6..057aad7 100644 (file)
@@ -81,14 +81,7 @@ struct DALI_SCENE_LOADER_API MeshDefinition
     Blob() = default;
 
     Blob(uint32_t offset, uint32_t length, uint16_t stride = 0, uint16_t elementSizeHint = 0,
-      const std::vector<float>& min = {}, const std::vector<float>& max = {})
-      : mOffset(offset),
-      mLength(length),
-      mStride(stride),
-      mElementSizeHint(elementSizeHint),
-      mMin(min),
-      mMax(max)
-    {}
+      const std::vector<float>& min = {}, const std::vector<float>& max = {});
 
     /**
      * @brief Calculates the size of a tightly-packed buffer for the elements from the blob.
index 994ec18..3dec499 100644 (file)
@@ -44,8 +44,7 @@ class ViewProjection;
 class DALI_SCENE_LOADER_API IResourceReceiver
 {
 public:
-  virtual ~IResourceReceiver()
-  {}
+  virtual ~IResourceReceiver() = default;
 
   virtual void Register(ResourceType::Value type, Index id) = 0;
 };
@@ -58,8 +57,7 @@ public:
 class DALI_SCENE_LOADER_API IResourceReflector
 {
 public:
-  virtual ~IResourceReflector()
-  {}
+  virtual ~IResourceReflector() = default;
 
   virtual void Reflect(ResourceType::Value type, Index& id) = 0;
 };
@@ -163,7 +161,7 @@ public:  // TYPES
     Index mShaderIdx = INVALID_INDEX;
 
   public: // METHODS
-    virtual ~Renderable() {}
+    virtual ~Renderable() = default;
 
     virtual void RegisterResources(IResourceReceiver& receiver) const;
     virtual void ReflectResources(IResourceReflector& reflector);
@@ -189,7 +187,7 @@ public:  // TYPES
     virtual void Finish(NodeDefinition& n) = 0;
 
   protected:
-    ~IVisitor() {}
+    ~IVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
   };
 
   class IConstVisitor
@@ -199,7 +197,7 @@ public:  // TYPES
     virtual void Finish(const NodeDefinition& n) = 0;
 
   protected:
-    ~IConstVisitor() {}
+    ~IConstVisitor() = default; // deliberately non-virtual these are transient objects and we don't want to pay for the vtable.
   };
 
   struct Extra
index 0bafc3b..409d285 100644 (file)
@@ -206,7 +206,7 @@ class ActorCreatorVisitor : public NodeDefinition::IConstVisitor
 {
 public:
   ActorCreatorVisitor(NodeDefinition::CreateParams& params)
-  :  mCreationContext(params)
+  : mCreationContext(params)
   {}
 
   void Start(const NodeDefinition& n)
@@ -400,7 +400,7 @@ SceneDefinition::SceneDefinition()
 }
 
 SceneDefinition::SceneDefinition(SceneDefinition&& other)
-:  mNodes(std::move(other.mNodes)),
+: mNodes(std::move(other.mNodes)),
   mRootNodeIds(std::move(other.mRootNodeIds))
 {
 #ifdef DEBUG_JOINTS
index 38dd628..415d25a 100644 (file)
@@ -39,6 +39,8 @@ struct DALI_SCENE_LOADER_API Skinning
    * @brief Name of bone matrix uniform (array).
    */
   static const std::string BONE_UNIFORM_NAME;
+
+  Skinning() = delete;
 };
 
 }
index 382e118..dbfb8e8 100644 (file)
@@ -35,6 +35,23 @@ namespace
 thread_local char sExceptionFlingerMessageBuffer[ExceptionFlinger::MESSAGE_BUFFER_SIZE]{};
 }
 
+StreamBuffer::StreamBuffer(char* buffer, size_t size) noexcept(true)
+{
+  setp(buffer, buffer + size);
+}
+
+ExceptionFlinger::ExceptionFlinger(const char* location) noexcept(true)
+: mLocation(location),
+  mStreamBuffer(GetMessageBuffer(), MESSAGE_BUFFER_SIZE - 1),
+  mStream(&mStreamBuffer)
+{}
+
+ExceptionFlinger::~ExceptionFlinger() noexcept(false)
+{
+  operator<<('\0');
+  throw DaliException(mLocation, GetMessageBuffer());
+}
+
 char* ExceptionFlinger::GetMessageBuffer() noexcept(true)
 {
   return sExceptionFlingerMessageBuffer;
index 3ab0c33..70009a2 100644 (file)
@@ -41,10 +41,7 @@ namespace SceneLoader
 class DALI_SCENE_LOADER_API StreamBuffer : public std::basic_streambuf<char>
 {
 public:
-  StreamBuffer(char* buffer, size_t size) noexcept(true)
-  {
-    setp(buffer, buffer + size);
-  }
+  StreamBuffer(char* buffer, size_t size) noexcept(true);
 };
 
 /*
@@ -57,18 +54,10 @@ class DALI_SCENE_LOADER_API ExceptionFlinger
 public:
   enum { MESSAGE_BUFFER_SIZE = 512 };
 
-  ExceptionFlinger(const char* location) noexcept(true)
-  : mLocation(location),
-    mStreamBuffer(GetMessageBuffer(), MESSAGE_BUFFER_SIZE - 1),
-    mStream(&mStreamBuffer)
-  {}
+  ExceptionFlinger(const char* location) noexcept(true);
 
   [[noreturn]]
-  ~ExceptionFlinger() noexcept(false)
-  {
-    operator<<('\0');
-    throw DaliException(mLocation, GetMessageBuffer());
-  }
+  ~ExceptionFlinger() noexcept(false);
 
   template <typename T>
   ExceptionFlinger& operator<<(const T& rhs) noexcept(true)