Add [[nodiscard]] attribute where meaningful
Mainly functions with zero side effects.
Change-Id: Ie812f9ad67bfd54f13aaae35932a6d00ca80cbd6
diff --git a/src/data_query.hpp b/src/data_query.hpp
index 7a54a33..e7b0c03 100644
--- a/src/data_query.hpp
+++ b/src/data_query.hpp
@@ -27,7 +27,7 @@
* \param listPath Path to the list (ending with a list_)
* \return A vector of maps, which represent the instances. The map is keyed by the name of the list key. The values in the map, are values of the list keys.
*/
- std::vector<ListInstance> listKeys(const dataPath_& listPath) const;
+ [[nodiscard]] std::vector<ListInstance> listKeys(const dataPath_& listPath) const;
private:
DatastoreAccess& m_datastore;
diff --git a/src/datastore_access.hpp b/src/datastore_access.hpp
index 5a9cdd1..8ff7658 100644
--- a/src/datastore_access.hpp
+++ b/src/datastore_access.hpp
@@ -30,7 +30,7 @@
public:
DatastoreException(const std::vector<DatastoreError>& errors);
~DatastoreException() override = default;
- const char* what() const noexcept override;
+ [[nodiscard]] const char* what() const noexcept override;
private:
std::string m_what;
@@ -44,7 +44,7 @@
public:
using Tree = std::vector<std::pair<std::string, leaf_data_>>;
virtual ~DatastoreAccess() = 0;
- virtual Tree getItems(const std::string& path) const = 0;
+ [[nodiscard]] virtual Tree getItems(const std::string& path) const = 0;
virtual void setLeaf(const std::string& path, leaf_data_ value) = 0;
virtual void createItem(const std::string& path) = 0;
virtual void deleteItem(const std::string& path) = 0;
@@ -56,7 +56,7 @@
virtual void commitChanges() = 0;
virtual void discardChanges() = 0;
virtual void copyConfig(const Datastore source, const Datastore destination) = 0;
- virtual std::string dump(const DataFormat format) const = 0;
+ [[nodiscard]] virtual std::string dump(const DataFormat format) const = 0;
private:
friend class DataQuery;
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index 85833f1..cd84983 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -259,7 +259,7 @@
private:
template <typename PathType>
- ReturnType impl(const PathType& suffix) const
+ [[nodiscard]] ReturnType impl(const PathType& suffix) const
{
PathType res = [this] {
if constexpr (std::is_same<PathType, schemaPath_>()) {
diff --git a/src/interpreter.hpp b/src/interpreter.hpp
index 4b4056e..543fb2e 100644
--- a/src/interpreter.hpp
+++ b/src/interpreter.hpp
@@ -31,13 +31,13 @@
void operator()(const dump_& dump) const;
private:
- std::string buildTypeInfo(const std::string& path) const;
+ [[nodiscard]] std::string buildTypeInfo(const std::string& path) const;
template <typename PathType>
boost::variant<dataPath_, schemaPath_, module_> toCanonicalPath(const boost::optional<PathType>& path) const;
template <typename PathType>
- boost::variant<dataPath_, schemaPath_, module_> toCanonicalPath(const PathType& path) const;
+ [[nodiscard]] boost::variant<dataPath_, schemaPath_, module_> toCanonicalPath(const PathType& path) const;
Parser& m_parser;
DatastoreAccess& m_datastore;
diff --git a/src/netconf-client.hpp b/src/netconf-client.hpp
index 2db21c9..5949704 100644
--- a/src/netconf-client.hpp
+++ b/src/netconf-client.hpp
@@ -33,7 +33,7 @@
static std::unique_ptr<Session> connectPubkey(const std::string& host, const uint16_t port, const std::string& user, const std::string& pubPath, const std::string& privPath);
static std::unique_ptr<Session> connectKbdInteractive(const std::string& host, const uint16_t port, const std::string& user, const KbdInteractiveCb& callback);
static std::unique_ptr<Session> connectSocket(const std::string& path);
- std::vector<std::string_view> capabilities() const;
+ [[nodiscard]] std::vector<std::string_view> capabilities() const;
std::shared_ptr<libyang::Data_Node> getConfig(const NC_DATASTORE datastore,
const std::optional<const std::string> filter = std::nullopt); // TODO: arguments...
std::shared_ptr<libyang::Data_Node> get(const std::optional<std::string>& filter = std::nullopt);
diff --git a/src/netconf_access.hpp b/src/netconf_access.hpp
index d9830bd..586840f 100644
--- a/src/netconf_access.hpp
+++ b/src/netconf_access.hpp
@@ -33,7 +33,7 @@
NetconfAccess(const std::string& socketPath);
NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session);
~NetconfAccess() override;
- Tree getItems(const std::string& path) const override;
+ [[nodiscard]] Tree getItems(const std::string& path) const override;
void setLeaf(const std::string& path, leaf_data_ value) override;
void createItem(const std::string& path) override;
void deleteItem(const std::string& path) override;
@@ -45,7 +45,7 @@
std::shared_ptr<Schema> schema() override;
- std::string dump(const DataFormat format) const override;
+ [[nodiscard]] std::string dump(const DataFormat format) const override;
private:
std::vector<ListInstance> listInstances(const std::string& path) override;
diff --git a/src/parser.hpp b/src/parser.hpp
index 1e8cdbb..052d5a9 100644
--- a/src/parser.hpp
+++ b/src/parser.hpp
@@ -36,7 +36,7 @@
Parser(const std::shared_ptr<const Schema> schema, WritableOps writableOps = WritableOps::No, const std::shared_ptr<const DataQuery> dataQuery = nullptr);
command_ parseCommand(const std::string& line, std::ostream& errorStream);
void changeNode(const dataPath_& name);
- std::string currentNode() const;
+ [[nodiscard]] std::string currentNode() const;
Completions completeCommand(const std::string& line, std::ostream& errorStream) const;
dataPath_ currentPath();
diff --git a/src/schema.hpp b/src/schema.hpp
index a1fd5b5..b103fd4 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -54,20 +54,20 @@
public:
virtual ~Schema();
- virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
- virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
- virtual bool isModule(const std::string& name) const = 0;
- virtual bool listHasKey(const schemaPath_& listPath, const std::string& key) const = 0;
- virtual bool leafIsKey(const std::string& leafPath) const = 0;
- virtual bool isConfig(const std::string& path) const = 0;
- virtual std::optional<std::string> defaultValue(const std::string& leafPath) const = 0;
- virtual const std::set<std::string> listKeys(const schemaPath_& listPath) const = 0;
- virtual yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
- virtual yang::TypeInfo leafType(const std::string& path) const = 0;
- virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
- virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
- virtual std::optional<std::string> description(const std::string& location) const = 0;
- virtual yang::Status status(const std::string& location) const = 0;
+ [[nodiscard]] virtual yang::NodeTypes nodeType(const std::string& path) const = 0;
+ [[nodiscard]] virtual yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
+ [[nodiscard]] virtual bool isModule(const std::string& name) const = 0;
+ [[nodiscard]] virtual bool listHasKey(const schemaPath_& listPath, const std::string& key) const = 0;
+ [[nodiscard]] virtual bool leafIsKey(const std::string& leafPath) const = 0;
+ [[nodiscard]] virtual bool isConfig(const std::string& path) const = 0;
+ [[nodiscard]] virtual std::optional<std::string> defaultValue(const std::string& leafPath) const = 0;
+ [[nodiscard]] virtual const std::set<std::string> listKeys(const schemaPath_& listPath) const = 0;
+ [[nodiscard]] virtual yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
+ [[nodiscard]] virtual yang::TypeInfo leafType(const std::string& path) const = 0;
+ [[nodiscard]] virtual std::optional<std::string> leafTypeName(const std::string& path) const = 0;
+ [[nodiscard]] virtual std::string leafrefPath(const std::string& leafrefPath) const = 0;
+ [[nodiscard]] virtual std::optional<std::string> description(const std::string& location) const = 0;
+ [[nodiscard]] virtual yang::Status status(const std::string& location) const = 0;
- virtual std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const = 0;
+ [[nodiscard]] virtual std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const = 0;
};
diff --git a/src/sysrepo_access.hpp b/src/sysrepo_access.hpp
index 016d49c..a3db4c1 100644
--- a/src/sysrepo_access.hpp
+++ b/src/sysrepo_access.hpp
@@ -28,7 +28,7 @@
public:
~SysrepoAccess() override;
SysrepoAccess(const std::string& appname, const Datastore datastore);
- Tree getItems(const std::string& path) const override;
+ [[nodiscard]] Tree getItems(const std::string& path) const override;
void setLeaf(const std::string& path, leaf_data_ value) override;
void createItem(const std::string& path) override;
void deleteItem(const std::string& path) override;
@@ -41,7 +41,7 @@
void discardChanges() override;
void copyConfig(const Datastore source, const Datastore destination) override;
- std::string dump(const DataFormat format) const override;
+ [[nodiscard]] std::string dump(const DataFormat format) const override;
private:
std::vector<ListInstance> listInstances(const std::string& path) override;
[[noreturn]] void reportErrors() const;
diff --git a/src/yang_access.hpp b/src/yang_access.hpp
index aaabd4b..075ba26 100644
--- a/src/yang_access.hpp
+++ b/src/yang_access.hpp
@@ -22,7 +22,7 @@
public:
YangAccess();
~YangAccess() override;
- Tree getItems(const std::string& path) const override;
+ [[nodiscard]] Tree getItems(const std::string& path) const override;
void setLeaf(const std::string& path, leaf_data_ value) override;
void createItem(const std::string& path) override;
void deleteItem(const std::string& path) override;
@@ -35,7 +35,7 @@
std::shared_ptr<Schema> schema() override;
void enableFeature(const std::string& module, const std::string& feature);
- std::string dump(const DataFormat format) const override;
+ [[nodiscard]] std::string dump(const DataFormat format) const override;
void loadModule(const std::string& name);
void addSchemaFile(const std::string& path);
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index 3663ccd..a527ef3 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -31,22 +31,22 @@
YangSchema(std::shared_ptr<libyang::Context> lyCtx);
~YangSchema() override;
- yang::NodeTypes nodeType(const std::string& path) const override;
- yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
- bool isModule(const std::string& name) const override;
- bool listHasKey(const schemaPath_& listPath, const std::string& key) const override;
- bool leafIsKey(const std::string& leafPath) const override;
- bool isConfig(const std::string& path) const override;
- std::optional<std::string> defaultValue(const std::string& leafPath) const override;
- const std::set<std::string> listKeys(const schemaPath_& listPath) const override;
- yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
- yang::TypeInfo leafType(const std::string& path) const override;
+ [[nodiscard]] yang::NodeTypes nodeType(const std::string& path) const override;
+ [[nodiscard]] yang::NodeTypes nodeType(const schemaPath_& location, const ModuleNodePair& node) const override;
+ [[nodiscard]] bool isModule(const std::string& name) const override;
+ [[nodiscard]] bool listHasKey(const schemaPath_& listPath, const std::string& key) const override;
+ [[nodiscard]] bool leafIsKey(const std::string& leafPath) const override;
+ [[nodiscard]] bool isConfig(const std::string& path) const override;
+ [[nodiscard]] std::optional<std::string> defaultValue(const std::string& leafPath) const override;
+ [[nodiscard]] const std::set<std::string> listKeys(const schemaPath_& listPath) const override;
+ [[nodiscard]] yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
+ [[nodiscard]] yang::TypeInfo leafType(const std::string& path) const override;
/** @brief If the leaf type is a typedef, returns the typedef name. */
- std::optional<std::string> leafTypeName(const std::string& path) const override;
- std::string leafrefPath(const std::string& leafrefPath) const override;
- std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const override;
- std::optional<std::string> description(const std::string& path) const override;
- yang::Status status(const std::string& location) const override;
+ [[nodiscard]] std::optional<std::string> leafTypeName(const std::string& path) const override;
+ [[nodiscard]] std::string leafrefPath(const std::string& leafrefPath) const override;
+ [[nodiscard]] std::set<ModuleNodePair> availableNodes(const boost::variant<dataPath_, schemaPath_, module_>& path, const Recursion recursion) const override;
+ [[nodiscard]] std::optional<std::string> description(const std::string& path) const override;
+ [[nodiscard]] yang::Status status(const std::string& location) const override;
void registerModuleCallback(const std::function<std::string(const char*, const char*, const char*, const char*)>& clb);
@@ -66,23 +66,23 @@
void addSchemaDirectory(const char* directoryName);
/** @short Creates a new data node from a path (to be used with NETCONF edit-config) */
- std::shared_ptr<libyang::Data_Node> dataNodeFromPath(const std::string& path, const std::optional<const std::string> value = std::nullopt) const;
+ [[nodiscard]] std::shared_ptr<libyang::Data_Node> dataNodeFromPath(const std::string& path, const std::optional<const std::string> value = std::nullopt) const;
std::shared_ptr<libyang::Module> getYangModule(const std::string& name);
private:
template <typename NodeType>
- yang::TypeInfo impl_leafType(const std::shared_ptr<libyang::Schema_Node>& node) const;
- std::set<std::string> modules() const;
+ [[nodiscard]] yang::TypeInfo impl_leafType(const std::shared_ptr<libyang::Schema_Node>& node) const;
+ [[nodiscard]] std::set<std::string> modules() const;
/** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
- std::shared_ptr<libyang::Schema_Node> getSchemaNode(const std::string& node) const;
+ [[nodiscard]] std::shared_ptr<libyang::Schema_Node> getSchemaNode(const std::string& node) const;
/** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
- std::shared_ptr<libyang::Schema_Node> getSchemaNode(const schemaPath_& listPath) const;
+ [[nodiscard]] std::shared_ptr<libyang::Schema_Node> getSchemaNode(const schemaPath_& listPath) const;
/** @short Returns a single Schema_Node if the criteria matches only one, otherwise nullptr. */
- std::shared_ptr<libyang::Schema_Node> getSchemaNode(const schemaPath_& location, const ModuleNodePair& node) const;
+ [[nodiscard]] std::shared_ptr<libyang::Schema_Node> getSchemaNode(const schemaPath_& location, const ModuleNodePair& node) const;
std::shared_ptr<libyang::Context> m_context;
- std::shared_ptr<libyang::Schema_Node> impl_getSchemaNode(const std::string& node) const;
+ [[nodiscard]] std::shared_ptr<libyang::Schema_Node> impl_getSchemaNode(const std::string& node) const;
};