Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constexpr additions #485

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: CMake

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down Expand Up @@ -41,7 +39,7 @@ jobs:
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
if [ ${{ matrix.os }} == 'windows-latest' ]; then
cmake -DTEST=ON -Dgtest_disable_pthreads=ON -B ${{github.workspace}}/build
cmake -DTEST=ON -Dgtest_disable_pthreads=ON -B ./build
else
cmake -DTEST=ON -B ${{github.workspace}}/build
fi;
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ packaging/
.vscode
.code-workspace
CXXGraph.code-workspace
# ignore Visual Studio files
/.vs
8 changes: 4 additions & 4 deletions include/CXXGraph/CXXGraphConfig.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// the configured options and settings for CXXGraph
#define CXXGraph_VERSION_MAJOR 4
#define CXXGraph_VERSION_MINOR 1
#define CXXGraph_VERSION_PATCH 0
// the configured options and settings for CXXGraph
#define CXXGraph_VERSION_MAJOR 4
#define CXXGraph_VERSION_MINOR 1
#define CXXGraph_VERSION_PATCH 0
6 changes: 3 additions & 3 deletions include/CXXGraph/Edge/DirectedEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
/*** License: MPL v2.0 ***/
/***********************************************************/

#ifndef __CXXGRAPH_DIRECTEDEDGE_H__
#define __CXXGRAPH_DIRECTEDEDGE_H__
#ifndef CXXGRAPH_DIRECTEDEDGE_H
#define CXXGRAPH_DIRECTEDEDGE_H

#pragma once

#include "DirectedEdge_impl.hpp"

#endif // __CXXGRAPH_DIRECTEDEDGE_H__
#endif // CXXGRAPH_DIRECTEDEDGE_H
22 changes: 12 additions & 10 deletions include/CXXGraph/Edge/DirectedEdge_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
/*** License: MPL v2.0 ***/
/***********************************************************/

#ifndef __CXXGRAPH_DIRECTEDEDGE_DECL_H__
#define __CXXGRAPH_DIRECTEDEDGE_DECL_H__
#ifndef CXXGRAPH_DIRECTEDEDGE_DECL_H_
#define CXXGRAPH_DIRECTEDEDGE_DECL_H_

#pragma once

Expand All @@ -42,19 +42,21 @@ std::ostream &operator<<(std::ostream &o, const DirectedEdge<T> &edge);
template <typename T>
class DirectedEdge : public Edge<T> {
public:
DirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
constexpr DirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
const Node<T> &node2);
DirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
constexpr DirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
shared<const Node<T>> node2);
DirectedEdge(const CXXGraph::id_t id,
constexpr DirectedEdge(
const CXXGraph::id_t id,
const std::pair<const Node<T> *, const Node<T> *> &nodepair);
DirectedEdge(
constexpr DirectedEdge(
const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
DirectedEdge(const Edge<T> &edge);
constexpr DirectedEdge(const Edge<T> &edge);
virtual ~DirectedEdge() = default;
const Node<T> &getFrom() const;
const Node<T> &getTo() const;
constexpr const Node<T> &getFrom() const;
constexpr const Node<T> &getTo() const;
//
const std::optional<bool> isDirected() const override;
const std::optional<bool> isWeighted() const override;
// operator
Expand All @@ -67,4 +69,4 @@ class DirectedEdge : public Edge<T> {
};
} // namespace CXXGraph

#endif // __CXXGRAPH_DIRECTEDEDGE_H__
#endif // CXXGRAPH_DIRECTEDEDGE_H_
18 changes: 8 additions & 10 deletions include/CXXGraph/Edge/DirectedEdge_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,42 @@

namespace CXXGraph {

using std::make_shared;
using std::make_unique;

template <typename T>
DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
constexpr DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id,
const Node<T> &node1,
const Node<T> &node2)
: Edge<T>(id, node1, node2) {}

template <typename T>
DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id,
constexpr DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id,
shared<const Node<T>> node1,
shared<const Node<T>> node2)
: Edge<T>(id, node1, node2) {}

template <typename T>
DirectedEdge<T>::DirectedEdge(
constexpr DirectedEdge<T>::DirectedEdge(
const CXXGraph::id_t id,
const std::pair<const Node<T> *, const Node<T> *> &nodepair)
: Edge<T>(id, nodepair) {}

template <typename T>
DirectedEdge<T>::DirectedEdge(
constexpr DirectedEdge<T>::DirectedEdge(
const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair)
: Edge<T>(id, nodepair) {}

template <typename T>
DirectedEdge<T>::DirectedEdge(const Edge<T> &edge)
constexpr DirectedEdge<T>::DirectedEdge(const Edge<T> &edge)
: DirectedEdge(edge.getId(), *(edge.getNodePair().first),
*(edge.getNodePair().second)) {}

template <typename T>
const Node<T> &DirectedEdge<T>::getFrom() const {
constexpr const Node<T> &DirectedEdge<T>::getFrom() const {
return *(Edge<T>::getNodePair().first);
}

template <typename T>
const Node<T> &DirectedEdge<T>::getTo() const {
constexpr const Node<T> &DirectedEdge<T>::getTo() const {
return *(Edge<T>::getNodePair().second);
}

Expand Down
6 changes: 3 additions & 3 deletions include/CXXGraph/Edge/DirectedWeightedEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
/***********************************************************/
/*** License: MPL v2.0 ***/
/***********************************************************/
#ifndef __CXXGRAPH_DIRECTEDWEIGHTEDEDGE_H__
#define __CXXGRAPH_DIRECTEDWEIGHTEDEDGE_H__
#ifndef CXXGRAPH_DIRECTEDWEIGHTEDEDGE_H_
#define CXXGRAPH_DIRECTEDWEIGHTEDEDGE_H_

#pragma once

#include "DirectedWeightedEdge_impl.hpp"

#endif // __CXXGRAPH_DIRECTEDWEIGHTEDEDGE_H__
#endif // CXXGRAPH_DIRECTEDWEIGHTEDEDGE_H_
28 changes: 15 additions & 13 deletions include/CXXGraph/Edge/DirectedWeightedEdge_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/***********************************************************/
/*** License: MPL v2.0 ***/
/***********************************************************/
#ifndef __CXXGRAPH_DIRECTEDWEIGHTEDEDGE_DECL_H__
#define __CXXGRAPH_DIRECTEDWEIGHTEDEDGE_DECL_H__
#ifndef CXXGRAPH_DIRECTEDWEIGHTEDEDGE_DECL_H_
#define CXXGRAPH_DIRECTEDWEIGHTEDEDGE_DECL_H_

#pragma once

Expand All @@ -31,7 +31,7 @@ using unique = std::unique_ptr<T>;
template <typename T>
using shared = std::shared_ptr<T>;

// Foward Declaration
// Forward Declaration
template <typename T>
class UndirectedWeightedEdge;

Expand All @@ -45,23 +45,25 @@ std::ostream &operator<<(std::ostream &o, const DirectedWeightedEdge<T> &edge);
template <typename T>
class DirectedWeightedEdge : public DirectedEdge<T>, public Weighted {
public:
DirectedWeightedEdge(const CXXGraph::id_t id, const Node<T> &node1,
constexpr DirectedWeightedEdge(const CXXGraph::id_t id, const Node<T> &node1,
const Node<T> &node2, const double weight);
DirectedWeightedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
constexpr DirectedWeightedEdge(const CXXGraph::id_t id,
shared<const Node<T>> node1,
shared<const Node<T>> node2, const double weight);
DirectedWeightedEdge(
constexpr DirectedWeightedEdge(
const CXXGraph::id_t id,
const std::pair<const Node<T> *, const Node<T> *> &nodepair,
const double weight);
DirectedWeightedEdge(
constexpr DirectedWeightedEdge(
const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair,
const double weight);
DirectedWeightedEdge(const DirectedEdge<T> &edge, const double weight);
DirectedWeightedEdge(const Edge<T> &edge, const double weight);
DirectedWeightedEdge(const DirectedEdge<T> &edge);
DirectedWeightedEdge(const Edge<T> &edge);
DirectedWeightedEdge(const UndirectedWeightedEdge<T> &edge);
constexpr DirectedWeightedEdge(const DirectedEdge<T> &edge,
const double weight);
constexpr DirectedWeightedEdge(const Edge<T> &edge, const double weight);
constexpr DirectedWeightedEdge(const DirectedEdge<T> &edge);
constexpr DirectedWeightedEdge(const Edge<T> &edge);
constexpr DirectedWeightedEdge(const UndirectedWeightedEdge<T> &edge);
virtual ~DirectedWeightedEdge() = default;
const std::optional<bool> isWeighted() const override;
// operator
Expand All @@ -76,4 +78,4 @@ class DirectedWeightedEdge : public DirectedEdge<T>, public Weighted {

} // namespace CXXGraph

#endif // __CXXGRAPH_DIRECTEDWEIGHTEDEDGE_DECL_H__
#endif // CXXGRAPH_DIRECTEDWEIGHTEDEDGE_DECL_H_
24 changes: 12 additions & 12 deletions include/CXXGraph/Edge/DirectedWeightedEdge_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,57 @@

namespace CXXGraph {

using std::make_shared;
using std::make_unique;

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(const CXXGraph::id_t id,
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(const CXXGraph::id_t id,
const Node<T> &node1,
const Node<T> &node2,
const double weight)
: DirectedEdge<T>(id, node1, node2), Weighted(weight) {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(const CXXGraph::id_t id,
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(
const CXXGraph::id_t id,
shared<const Node<T>> node1,
shared<const Node<T>> node2,
const double weight)
: DirectedEdge<T>(id, node1, node2), Weighted(weight) {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(
const CXXGraph::id_t id,
const std::pair<const Node<T> *, const Node<T> *> &nodepair,
const double weight)
: DirectedEdge<T>(id, nodepair), Weighted(weight) {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(
const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair,
const double weight)
: DirectedEdge<T>(id, nodepair), Weighted(weight) {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(const DirectedEdge<T> &edge,
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(
const DirectedEdge<T> &edge,
const double weight)
: DirectedEdge<T>(edge), Weighted(weight) {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(const Edge<T> &edge,
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(const Edge<T> &edge,
const double weight)
: DirectedEdge<T>(edge), Weighted(weight) {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(const DirectedEdge<T> &edge)
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(
const DirectedEdge<T> &edge)
: DirectedEdge<T>(edge), Weighted() {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(const Edge<T> &edge)
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(const Edge<T> &edge)
: DirectedEdge<T>(edge), Weighted() {}

template <typename T>
DirectedWeightedEdge<T>::DirectedWeightedEdge(
constexpr DirectedWeightedEdge<T>::DirectedWeightedEdge(
const UndirectedWeightedEdge<T> &edge)
: DirectedEdge<T>(edge), Weighted(edge.getWeight()) {}

Expand Down
6 changes: 3 additions & 3 deletions include/CXXGraph/Edge/Edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
/*** License: MPL v2.0 ***/
/***********************************************************/

#ifndef __CXXGRAPH_EDGE_H__
#define __CXXGRAPH_EDGE_H__
#ifndef CXXGRAPH_EDGE_H_
#define CXXGRAPH_EDGE_H_

#pragma once

#include "CXXGraph/Edge/Edge_impl.hpp"

#endif // __CXXGRAPH_EDGE_H__
#endif // CXXGRAPH_EDGE_H_
19 changes: 10 additions & 9 deletions include/CXXGraph/Edge/Edge_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
/*** License: MPL v2.0 ***/
/***********************************************************/

#ifndef __CXXGRAPH_EDGE_DECL_H__
#define __CXXGRAPH_EDGE_DECL_H__
#ifndef CXXGRAPH_EDGE_DECL_H_
#define CXXGRAPH_EDGE_DECL_H_

#pragma once

Expand Down Expand Up @@ -49,29 +49,30 @@ class Edge {
public:
typedef T Node_t;

Edge(const CXXGraph::id_t id, const Node<T> &node1, const Node<T> &node2);
Edge(const CXXGraph::id_t id, shared<const Node<T>> node1,
constexpr Edge(const CXXGraph::id_t id, const Node<T> &node1, const Node<T> &node2);
constexpr Edge(const CXXGraph::id_t id, shared<const Node<T>> node1,
shared<const Node<T>> node2);
Edge(const CXXGraph::id_t id,
constexpr Edge(const CXXGraph::id_t id,
const std::pair<const Node<T> *, const Node<T> *> &nodepair);
Edge(const CXXGraph::id_t id,
constexpr Edge(
const CXXGraph::id_t id,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
virtual ~Edge() = default;
void setFirstNode(shared<const Node<T>> node);
void setSecondNode(shared<const Node<T>> node);
unsigned long long getId() const;
constexpr unsigned long long getId() const;
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &getNodePair()
const;
shared<const Node<T>> getOtherNode(shared<const Node<T>> node) const;
virtual const std::optional<bool> isDirected() const;
virtual const std::optional<bool> isWeighted() const;
// operator
virtual bool operator==(const Edge<T> &b) const;
bool operator<(const Edge<T> &b) const;
constexpr bool operator<(const Edge<T> &b) const;

friend std::ostream &operator<< <>(std::ostream &os, const Edge<T> &edge);
};

} // namespace CXXGraph

#endif // __CXXGRAPH_EDGE_DECL_H__
#endif // CXXGRAPH_EDGE_DECL_H_
Loading
Loading