Skip to content

Commit

Permalink
Merge branch 'modernize-trailing-return-types' into 'main'
Browse files Browse the repository at this point in the history
Modernize codebase with trailing return types

See merge request educelab/smgl!14
  • Loading branch information
csparker247 committed Feb 7, 2024
2 parents 2ff0bad + 9cd76dc commit 014be64
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 213 deletions.
2 changes: 1 addition & 1 deletion cmake/FindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ option(SMGL_BUILD_JSON "Build in-source JSON library" ON)
if(SMGL_BUILD_JSON)
FetchContent_Declare(
json
URL https://github.com/nlohmann/json/archive/v3.11.2.tar.gz
URL https://github.com/nlohmann/json/archive/v3.11.3.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP ON
)

Expand Down
49 changes: 26 additions & 23 deletions smgl/include/smgl/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class Graph : public UniquelyIdentifiable
enum class State { Idle, Updating, Error };

/** @brief Get a Node by Uuid */
Node::Pointer operator[](const Uuid& uuid) const;
auto operator[](const Uuid& uuid) const -> Node::Pointer;

/** @brief Add a Node to the Graph */
void insertNode(const Node::Pointer& n);

/** @brief Construct a Node and add it to the graph */
template <typename NodeType, typename... Args>
std::shared_ptr<NodeType> insertNode(Args... args);
auto insertNode(Args... args) -> std::shared_ptr<NodeType>;

/** @brief Add one or more Nodes to the Graph */
template <typename N, typename... Ns>
Expand All @@ -55,10 +55,10 @@ class Graph : public UniquelyIdentifiable
void removeNode(const Node::Pointer& n);

/** @brief Get the number of nodes in the graph */
std::size_t size() const;
auto size() const -> std::size_t;

/** @brief Get the current graph state */
State state() const;
auto state() const -> State;

/**
* @brief Get the root cache file for the Graph
Expand All @@ -67,7 +67,7 @@ class Graph : public UniquelyIdentifiable
* subdirectory in cacheDir(). The exact location is relative to cacheFile()
* and is determined by setCacheType().
*/
filesystem::path cacheFile() const;
auto cacheFile() const -> filesystem::path;

/**
* @brief Set the root cache file for the Graph
Expand All @@ -82,7 +82,7 @@ class Graph : public UniquelyIdentifiable
* A graph's CacheType determines the location of the cache relative to
* cacheFile().
*/
CacheType cacheType() const;
auto cacheType() const -> CacheType;

/**
* @brief Set the graph's CacheType
Expand All @@ -95,14 +95,14 @@ class Graph : public UniquelyIdentifiable
* @brief Returns the cache directory as configured by cacheFile() and
* cacheType()
*/
filesystem::path cacheDir() const;
auto cacheDir() const -> filesystem::path;

/**
* @brief Whether or not graph caching is enabled
*
* @copydetails cacheFile()
*/
bool cacheEnabled() const;
auto cacheEnabled() const -> bool;

/**
* @brief Set whether or not graph caching is enabled
Expand All @@ -115,25 +115,25 @@ class Graph : public UniquelyIdentifiable
void setProjectMetadata(const Metadata& m);

/** @brief Get the project metadata */
const Metadata& projectMetadata() const;
auto projectMetadata() const -> const Metadata&;

/** @copydoc projectMetadata() const */
Metadata& projectMetadata();
auto projectMetadata() -> Metadata&;

/**
* @brief Update the Graph's nodes
*
* Schedules the Nodes of the Graph and update them as needed.
*/
State update();
auto update() -> State;

/**
* @brief Serialize a Graph to a Metadata object
*
* @warning This function honors the value of cacheEnabled() and will write
* data to cacheDir().
*/
static Metadata Serialize(const Graph& g);
static auto Serialize(const Graph& g) -> Metadata;

/**
* @brief Save a Graph to a JSON file
Expand All @@ -145,8 +145,9 @@ class Graph : public UniquelyIdentifiable
* @param g Graph to be saved
* @param writeCache Whether or not to write cache files
*/
static void Save(
const filesystem::path& path, const Graph& g, bool writeCache = false);
static auto Save(
const filesystem::path& path, const Graph& g, bool writeCache = false)
-> void;

/**
* @brief Load a Graph from a JSON file
Expand All @@ -157,7 +158,7 @@ class Graph : public UniquelyIdentifiable
*
* @param path Path to input file in the JSON format
*/
static Graph Load(const filesystem::path& path);
static auto Load(const filesystem::path& path) -> Graph;

/**
* @brief Checks that a Graph JSON file can be loaded
Expand All @@ -169,8 +170,8 @@ class Graph : public UniquelyIdentifiable
* @param path Path to input file in the JSON format
* @return List of Node types that are not registered for serialization
*/
static std::vector<std::string> CheckRegistration(
const filesystem::path& path);
static auto CheckRegistration(const filesystem::path& path)
-> std::vector<std::string>;

/**
* @brief Checks that a Graph can be serialized
Expand All @@ -184,7 +185,7 @@ class Graph : public UniquelyIdentifiable
* @param g Graph to be checked
* @return List of Node types that are not registered for serialization
*/
static std::vector<std::string> CheckRegistration(const Graph& g);
static auto CheckRegistration(const Graph& g) -> std::vector<std::string>;

/**
* @brief Generate an update schedule for the provided Graph
Expand All @@ -193,7 +194,7 @@ class Graph : public UniquelyIdentifiable
* Nodes. Graph must have at least one Node with no input connections and
* must be acyclic.
*/
static std::vector<Node::Pointer> Schedule(const Graph& g);
static auto Schedule(const Graph& g) -> std::vector<Node::Pointer>;

private:
/** Cache file */
Expand All @@ -210,12 +211,14 @@ class Graph : public UniquelyIdentifiable
Metadata extraMetadata_;

/** Perform graph serialization */
static Metadata Serialize(
const Graph& g, bool useCache, const filesystem::path& cacheDir);
static auto Serialize(
const Graph& g, bool useCache, const filesystem::path& cacheDir)
-> Metadata;

/** Friend function: Graphviz WriteDotFile */
friend void WriteDotFile(
const filesystem::path& path, const Graph& g, const GraphStyle& style);
friend auto WriteDotFile(
const filesystem::path& path, const Graph& g, const GraphStyle& style)
-> void;
};

} // namespace smgl
Expand Down
4 changes: 2 additions & 2 deletions smgl/include/smgl/GraphImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ namespace smgl
{

template <typename NodeType, typename... Args>
std::shared_ptr<NodeType> Graph::insertNode(Args... args)
auto Graph::insertNode(Args... args) -> std::shared_ptr<NodeType>
{
auto n = std::make_shared<NodeType>(std::forward<Args>(args)...);
insertNode(n);
return n;
}

template <typename N, typename... Ns>
void Graph::insertNodes(N& n0, Ns&&... nodes)
auto Graph::insertNodes(N& n0, Ns&&... nodes) -> void
{
insertNode(n0);
#if __cplusplus >= 201703L
Expand Down
56 changes: 28 additions & 28 deletions smgl/include/smgl/Graphviz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct FontStyle {
/** @brief Font typeface */
std::string face;
/** @brief Returns whether or not this style has an values set */
bool empty() const { return color.empty() and face.empty(); }
auto empty() const -> bool { return color.empty() and face.empty(); }
};

/** @brief Style struct containing all sub-styles for a node */
Expand Down Expand Up @@ -112,9 +112,9 @@ class GraphStyle
/** @brief Set the default node style */
void setDefaultStyle(const NodeStyle& style);
/** @brief Access the default node style */
NodeStyle& defaultStyle();
auto defaultStyle() -> NodeStyle&;
/** @copydoc defaultStyle() */
const NodeStyle& defaultStyle() const;
auto defaultStyle() const -> const NodeStyle&;
/** @} */

/**
Expand All @@ -137,10 +137,10 @@ class GraphStyle
template <class NodeT>
void setClassStyle(const NodeStyle& style);
/** @brief Check if a class of nodes has an associated style */
bool hasClassStyle(const std::string& name) const;
auto hasClassStyle(const std::string& name) const -> bool;
/** @copydoc hasClassStyle() */
template <class NodeT>
bool hasClassStyle() const;
auto hasClassStyle() const -> bool;
/** @brief Erase the style associated with a class of nodes */
void eraseClassStyle(const std::string& name);
/** @copydoc eraseClassStyle() */
Expand All @@ -151,19 +151,19 @@ class GraphStyle
*
* If a style has not been set, one is created and returned.
*/
NodeStyle& classStyle(const std::string& name);
auto classStyle(const std::string& name) -> NodeStyle&;
/** @copydoc classStyle(const std::string&) */
template <class NodeT>
NodeStyle& classStyle();
auto classStyle() -> NodeStyle&;
/**
* @copybrief classStyle(const std::string&)
*
* @throws std::out_of_range if a style has not been set
*/
const NodeStyle& classStyle(const std::string& name) const;
auto classStyle(const std::string& name) const -> const NodeStyle&;
/** @copydoc classStyle(const std::string&) const */
template <class NodeT>
const NodeStyle& classStyle() const;
auto classStyle() const -> const NodeStyle&;
/** @} */

/**
Expand All @@ -184,9 +184,9 @@ class GraphStyle
/** @copydoc setInstanceStyle() */
void setInstanceStyle(const Node* node, const NodeStyle& style);
/** @brief Check if a node has an associated instance style */
bool hasInstanceStyle(const Node::Pointer& node) const;
auto hasInstanceStyle(const Node::Pointer& node) const -> bool;
/** @copydoc hasInstanceStyle() */
bool hasInstanceStyle(const Node* node) const;
auto hasInstanceStyle(const Node* node) const -> bool;
/** @brief Erase the style associated with a node instance */
void eraseInstanceStyle(const Node::Pointer& node);
/** @copydoc eraseInstanceStyle */
Expand All @@ -196,17 +196,17 @@ class GraphStyle
*
* If a style has not been set, one is created and returned.
*/
NodeStyle& instanceStyle(const Node::Pointer& node);
auto instanceStyle(const Node::Pointer& node) -> NodeStyle&;
/**
* @copybrief instanceStyle
*
* @throws std::out_of_range if a style has not been set
*/
const NodeStyle& instanceStyle(const Node::Pointer& node) const;
auto instanceStyle(const Node::Pointer& node) const -> const NodeStyle&;
/** @copydoc instanceStyle() */
NodeStyle& instanceStyle(const Node* node);
auto instanceStyle(const Node* node) -> NodeStyle&;
/** @copydoc instanceStyle(const Node::Pointer&) const */
const NodeStyle& instanceStyle(const Node* node) const;
auto instanceStyle(const Node* node) const -> const NodeStyle&;
/** @} */

/**
Expand All @@ -217,9 +217,9 @@ class GraphStyle
*/
/** @{ */
/** @brief Get the evaluated node style for a specific node */
NodeStyle nodeStyle(const Node::Pointer& node) const;
auto nodeStyle(const Node::Pointer& node) const -> NodeStyle;
/** @copybrief nodeStyle() */
NodeStyle nodeStyle(const Node* node) const;
auto nodeStyle(const Node* node) const -> NodeStyle;
/** @} */

/**
Expand Down Expand Up @@ -260,7 +260,7 @@ class GraphStyle
* with appendRankSame().
*/
template <typename... Args>
std::size_t setRankSame(const Args&... args);
auto setRankSame(const Args&... args) -> std::size_t;

/**
* @brief Assign node(s) to an existing group ranking
Expand All @@ -272,29 +272,29 @@ class GraphStyle
void appendRankSame(T idx, const Args&... args);

/** @brief Get the set of nodes assigned to the minimum rank */
std::unordered_set<Uuid>& rankMin();
auto rankMin() -> std::unordered_set<Uuid>&;
/** @copydoc rankMin() */
const std::unordered_set<Uuid>& rankMin() const;
auto rankMin() const -> const std::unordered_set<Uuid>&;

/** @brief Get the set of nodes assigned to the source rank */
std::unordered_set<Uuid>& rankSource();
auto rankSource() -> std::unordered_set<Uuid>&;
/** @copydoc rankSource() */
const std::unordered_set<Uuid>& rankSource() const;
auto rankSource() const -> const std::unordered_set<Uuid>&;

/** @brief Get the set of nodes assigned to the maximum rank */
std::unordered_set<Uuid>& rankMax();
auto rankMax() -> std::unordered_set<Uuid>&;
/** @copydoc rankMax() */
const std::unordered_set<Uuid>& rankMax() const;
auto rankMax() const -> const std::unordered_set<Uuid>&;

/** @brief Get the set of nodes assigned to the sink rank */
std::unordered_set<Uuid>& rankSink();
auto rankSink() -> std::unordered_set<Uuid>&;
/** @copydoc rankSink() */
const std::unordered_set<Uuid>& rankSink() const;
auto rankSink() const -> const std::unordered_set<Uuid>&;

/** @brief Get the set of rank groups */
std::vector<std::vector<Uuid>>& rankSame();
auto rankSame() -> std::vector<std::vector<Uuid>>&;
/** @copydoc rankSame() */
const std::vector<std::vector<Uuid>>& rankSame() const;
auto rankSame() const -> const std::vector<std::vector<Uuid>>&;
/** @} */

private:
Expand Down
8 changes: 4 additions & 4 deletions smgl/include/smgl/GraphvizImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void GraphStyle::setClassStyle(const NodeStyle& style)
}

template <class NodeT>
bool GraphStyle::hasClassStyle() const
auto GraphStyle::hasClassStyle() const -> bool
{
return hasClassStyle(NodeName<NodeT>());
}
Expand All @@ -22,13 +22,13 @@ void GraphStyle::eraseClassStyle() const
}

template <class NodeT>
NodeStyle& GraphStyle::classStyle()
auto GraphStyle::classStyle() -> NodeStyle&
{
return classStyle(NodeName<NodeT>());
}

template <class NodeT>
const NodeStyle& GraphStyle::classStyle() const
auto GraphStyle::classStyle() const -> const NodeStyle&
{
return classStyle(NodeName<NodeT>());
}
Expand Down Expand Up @@ -106,7 +106,7 @@ void GraphStyle::setRankSink(const Args&... args)
}

template <typename... Args>
std::size_t GraphStyle::setRankSame(const Args&... args)
auto GraphStyle::setRankSame(const Args&... args) -> std::size_t
{
static_assert(sizeof...(args) > 0, "Missing arguments");
using namespace type_traits;
Expand Down
2 changes: 1 addition & 1 deletion smgl/include/smgl/Logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void SetLogLevel(LogLevel level);
void SetLogLevel(const std::string& level);

/** @brief Get the library log level */
LogLevel GetLogLevel();
auto GetLogLevel() -> LogLevel;

/** @brief Set the output stream */
void SetLogStream(std::ostream* os);
Expand Down
Loading

0 comments on commit 014be64

Please sign in to comment.