[Props] Add concept of empty to property
authorJihoon Lee <jhoon.it.lee@samsung.com>
Fri, 21 May 2021 08:48:15 +0000 (17:48 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 23 Jun 2021 07:42:19 +0000 (16:42 +0900)
This patch adds empty concept to property instead of having insensible
value inside a property as a default

before this patch,
```cpp
auto a = Property<int>();
EXPECT_EQ(a.get(), -1); // let's assume -1 is default value which might not be sensible.
```
after this patch

```cpp
auto a = Property<int>();
EXPECT_THROW(a.get(), std::invalid_argument);
EXPECT_TRUE(a.empty());
```

so underlying value remains always null or valid.

Now, it became natural to distinguish mandatory props and non-mandatory
props

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/layers/layer_node.h

index b0768aa..f911cb0 100644 (file)
@@ -92,20 +92,7 @@ public:
    * @note      This name might be changed once this layer is added to the model
    * to keep the name unique to the model
    */
-  const std::string getName() const noexcept {
-    auto &name = std::get<props::Name>(props);
-    return name.empty() ? "" : name.get();
-  }
-
-  /**
-   * @brief     Get name of the layer
-   *
-   * @retval    name of the layer
-   * @note      This name is unique to this layer in a model
-   * @note      This name might be changed once this layer is added to the model
-   * to keep the name unique to the model
-   */
-  std::string getName() noexcept {
+  const std::string getName() const noexcept override {
     auto &name = std::get<props::Name>(props);
     return name.empty() ? "" : name.get();
   }