Skip to content

Commit

Permalink
Let's check for a running workflow by force And Cleanup later 3
Browse files Browse the repository at this point in the history
  • Loading branch information
franziska-wegner committed Dec 5, 2023
1 parent 01cf858 commit 1300bce
Show file tree
Hide file tree
Showing 4 changed files with 1,508 additions and 0 deletions.
168 changes: 168 additions & 0 deletions include/DataStructures/Bound.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Bound.hpp
*
* Created on: Sep 06, 2018
* Author: Franziska Wegner
*/

#ifndef EGOA__DATA_STRUCTURE__BOUND_HPP
#define EGOA__DATA_STRUCTURE__BOUND_HPP

#include "Exceptions/Exceptions.hpp"
#include "Exceptions/Assertions.hpp"

namespace egoa {

/**
* @brief Class for bounds.
*
* @tparam BoundType The type of the lower and upper bounds.
*/
template<typename BoundType = double>
class Bound {
private:
#pragma mark TYPE_ALIASING
using TBound = BoundType; /**< The bound type, e.g., int. */

public:
/**@name Constructors and Destructor */
///@{
#pragma mark CONSTRUCTORS_AND_DESTRUCTORS

Bound() = delete;

/**
* @brief Constructs the object.
*
* @param[in] minimum The minimum representing the lower bound.
* @param[in] maximum The maximum representing the upper bound.
*/
Bound ( TBound const & minimum
, TBound const & maximum )
: minimum_(minimum)
, maximum_(maximum)
{
#ifdef PGT_EXCEPTION_HANDLING
BoundMismatch::template Check<TBound>(minimum, maximum);
#endif
USAGE_ASSERT ( minimum_ <= maximum_ );
}
///@}

///@name Getter and Setter
///@{
#pragma mark GETTER_AND_SETTER

/**
* @brief Getter of the minimum of the bound.
*
* @return The minimum of the bound, i.e., lower bound.
*/
inline TBound Minimum () const
{
return minimum_;
}

/**
* @brief Setter of the minimum of the bound.
*
* @code{.cpp}
* someBound.Minimum() = 9;
* @endcode
*
* @return The minimum of the bound, i.e., lower bound.
*/
inline TBound & Minimum ()
{
return minimum_;
}

/**
* @brief Getter of the maximum of the bound.
*
* @return The maximum of the bound, i.e., upper bound.
*/
inline TBound Maximum() const
{
return maximum_;
}

/**
* @brief Setter of the maximum of the bound.
*
* @code{.cpp}
* someBound.Maximum() = 99;
* @endcode
*
* @return The maximum of the bound, i.e., upper bound.
*/
inline TBound & Maximum()
{
return maximum_;
}
///@}

///@name Modifier
///@{
#pragma mark MODIFIER

/**
* @brief Set the range of the bound.
*
* @param[in] minimum The minimum of the bound, i.e., lower bound.
* @param[in] maximum The maximum of the bound, i.e., upper bound.
*/
inline void Range ( TBound const & minimum
, TBound const & maximum )
{
#ifdef PGT_EXCEPTION_HANDLING
BoundMismatch::template Check<TBound>(minimum, maximum);
#endif
USAGE_ASSERT ( minimum <= maximum );
minimum_ = minimum;
maximum_ = maximum;

USAGE_ASSERT ( minimum_ <= maximum_ );
}
///@}

///@name Comparators
///@{
#pragma mark COMPARATORS

/**
* @brief Comparison operator.
*
* @param[in] rhs The right hand side Bound.
*
* @code{.cpp}
* if ( Bound<int>(0,0) == Bound<int>(1,0) ) { }
* @endcode
*
* @return @p True if both bounds are equal, @p False otherwise.
*/
inline bool operator== ( Bound<TBound> const & rhs ) const
{
return ( this->Minimum() == rhs.Minimum() )
&& ( this->Maximum() == rhs.Maximum() );
}

inline bool operator!= ( Bound<TBound> const & rhs ) const
{
return !(*this == rhs);
}
///@}

private:
///@name Members
///@{
#pragma mark MEMBERS

TBound minimum_; /**< The minimum of the bound representing the lower bound. */
TBound maximum_; /**< The maximum of the bound representing the upper bound. */
///@}
};

} // gpgt

#endif // EGOA__DATA_STRUCTURE__BOUND_HPP
81 changes: 81 additions & 0 deletions include/Exceptions/Exceptions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* PgtExceptions.hpp
*
* Created on: Nov 07, 2018
* Author: Franziska Wegner
*/

#ifndef EGOA__EXCEPTIONS__PGT_EXCEPTIONS_HPP
#define EGOA__EXCEPTIONS__PGT_EXCEPTIONS_HPP

#include <iostream>
#include <exception>
#include <stdexcept>
#include <sstream>
#include <string>

#include "Auxiliary/Types.hpp"

namespace egoa {

// https://stackoverflow.com/questions/348833/how-to-know-the-exact-line-of-code-where-where-an-exception-has-been-caused
template<typename T>
void my_exception(T arg1, T arg2, const char *file, const char *func, size_t line) {
#ifdef PGT_EXCEPTION_HANDLING
if ( arg1 < arg2 )
throw runtime_error( (std::string)file + ":" + (std::string)func + ":" + std::to_string(line) +
": index out of bound error with index:" + to_string(arg1) +
" > number of elements ( here " + to_string(arg2) + ")." );
#endif
}

#define throw_out_of_bound(arg1,arg2) throw my_exception(arg1, arg2, __FILE__, __func__, __LINE__);

// template<typename T = double>
class BoundMismatch : public std::runtime_error {
typedef double T;
public:
/// constructor only which passes message to base class
BoundMismatch(std::string msg, T minimum, T maximum)
: std::runtime_error(msg), minimum_(minimum), maximum_(maximum) {}

BoundMismatch(T minimum, T maximum)
: std::runtime_error("Minimum > maximum"), minimum_(minimum), maximum_(maximum) {

}

inline T Minimum() const { return minimum_; }
inline T& Minimum() { return minimum_; }

inline T Maximum() const { return maximum_; }
inline T& Maximum() { return maximum_; }

template<typename T2 = double>
static T2 Check(const T2& minimum, const T2& maximum)
{
if ( minimum > maximum ) {
throw BoundMismatch( minimum, maximum );
}
return true;
}

virtual Types::string What() const throw() {
std::ostringstream message;

message << runtime_error::what()
<< ": " << Minimum()
<< " < " << Maximum();

return message.str();
}

private:
double minimum_;
double maximum_;
};

// ostringstream BoundMismatch::message_;

} // namespace egoa

#endif // EGOA__EXCEPTIONS__PGT_EXCEPTIONS_HPP
Loading

0 comments on commit 1300bce

Please sign in to comment.