Skip to content

Commit

Permalink
#17: adl/oct: Create Component Unit adl/oct/traits
Browse files Browse the repository at this point in the history
- Module `adl/oct/traits` created
- Major corrections and some additions in the module `adl/oct/limits`
- Minor corrections in the module `adl/char_helper`
  • Loading branch information
flisboac committed Apr 17, 2017
1 parent 4632edd commit 1402e36
Show file tree
Hide file tree
Showing 8 changed files with 988 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ target_sources(${api} INTERFACE
"${api_dir_root}/adl/oct.fwd.hpp"
"${api_dir_root}/adl/oct/domain_space.hpp"
"${api_dir_root}/adl/oct/limits.hpp"
"${api_dir_root}/adl/oct/traits.hpp"

# adl/oct/dsl
"${api_dir_root}/adl/oct/dsl.hpp"
Expand Down Expand Up @@ -127,6 +128,7 @@ add_executable(${test}

# unit:adl/oct
"${test_dir_unit}/adl/oct/limits.unit.cpp"
"${test_dir_unit}/adl/oct/traits.unit.cpp"
)
target_link_libraries(${test} ${test_iapi})
enable_testing()
Expand Down
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,33 @@ SHELL := /bin/bash
RM := rm -rf
MKDIR := mkdir -p
BUILD_DIR := ./build
BUILD_DIRS := $(BUILD_DIR) cmake-build-* bin
SRC_DIR := ..

IDEA_FILES := .idea
ECLIPSE_FILES := .project .cproject .settings
KDEVELOP_FILES := *.kdev4 .kdev4

all: $(BUILD_DIR)/Makefile
$(MAKE) -C $(BUILD_DIR)

$(BUILD_DIR)/Makefile:
clean: $(BUILD_DIR)/Makefile
$(MAKE) -C $(BUILD_DIR) clean

distclean:
$(RM) $(BUILD_DIRS)

$(BUILD_DIR)/Makefile: CMakeLists.txt
$(MKDIR) $(BUILD_DIR) > /dev/null
cd $(BUILD_DIR) > /dev/null 2>&1 && cmake $(SRC_DIR)

distclean:
$(RM) $(BUILD_DIR)
eclipse-clean:
$(RM) $(ECLIPSE_FILES)

kdevelop-clean:
$(RM) $(KDEVELOP_FILES)

idea-clean:
$(RM) $(IDEA_FILES)

ide-clean: eclipse-clean kdevelop-clean idea-clean
10 changes: 5 additions & 5 deletions include/adl/char_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ struct adl_CLASS char_helper : public char_definitions<Char> {
noexcept(noexcept(String().empty()) && noexcept(String("")));
constexpr static const char_type* rfind(const char_type* p, std::size_t count, const char_type& ch);
constexpr static bool is_digit(const char_type& c) noexcept;
template <typename T = int> constexpr inline T digit_to_integer(const char_type& c) noexcept;
template <typename T> constexpr static T to_integer(T fallback_value, const char_type* c, size_t size = 0);
template <typename T = int> constexpr static T digit_to_integer(const char_type& c) noexcept;
template <typename T> constexpr static T to_integer(T fallback_value, const char_type* c, size_t size = 0) noexcept;

private:
constexpr static bool is_finished_(const char_type* s, size_t s_size, size_t s_count);
Expand All @@ -169,7 +169,7 @@ struct adl_CLASS char_helper : public char_definitions<Char> {
bool found = false,
bool negative = false,
char_digit_base base = char_digit_base::decimal
);
) noexcept;
};

template <typename... Args> adl_API int string_printf(std::string& buffer, const char* fmt, Args... args);
Expand Down Expand Up @@ -353,7 +353,7 @@ constexpr T char_helper<Char>::digit_to_integer(const char_type& c) noexcept {

template <typename Char>
template <typename T>
constexpr T char_helper<Char>::to_integer(T fallback_value, const char_type* c, size_t size) {
constexpr T char_helper<Char>::to_integer(T fallback_value, const char_type* c, size_t size) noexcept {
return choose_valid_(to_integer_(c, size, 0, T(0)), fallback_value);
}

Expand Down Expand Up @@ -423,7 +423,7 @@ constexpr std::pair<T, bool> char_helper<Char>::to_integer_(
bool found,
bool negative,
char_digit_base base
) {
) noexcept {
return !is_finished_(c, c_size, c_count)
? is_digit(c[c_count])
? to_integer_(
Expand Down
10 changes: 9 additions & 1 deletion include/adl/oct.fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum class domain_space;

using default_var_id_type = int;
template <typename ValueType> class value_limits;
template <domain_space Domain, typename VarIdType = default_var_id_type> struct var_id_limits;
template <domain_space Domain> struct var_id_limits;

/**
* The hard-limit maximum number of octagonal variables supported for a given variable id's type.
Expand All @@ -49,6 +49,14 @@ constexpr static std::size_t max_oct_variables =
template <typename VarIdType = default_var_id_type>
constexpr static std::size_t max_octdiff_variables = max_oct_variables<VarIdType> * 2;

//
// traits.hpp
//
template <typename ValueType, typename ValueLimits = value_limits<ValueType>> struct value_traits;
template <domain_space Domain, typename VarIdLimits = var_id_limits<Domain>> struct var_id_traits;
template <typename VarType> struct var_traits;


adl_END_MAIN_MODULE

#endif // adl__oct__fwd__hpp__
60 changes: 35 additions & 25 deletions include/adl/oct/limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ adl_BEGIN_MAIN_MODULE(oct)
*/
template <typename ValueType>
struct value_limits : public std::numeric_limits<ValueType> {
using value_type = ValueType;
using std::numeric_limits<ValueType>::has_infinity;
using std::numeric_limits<ValueType>::infinity;
using std::numeric_limits<ValueType>::max;
using std::numeric_limits<ValueType>::is_specialized;
constexpr static ValueType top();
};

Expand All @@ -34,13 +36,13 @@ struct value_limits : public std::numeric_limits<ValueType> {
* @tparam Domain The domain to which the limits apply.
* @tparam VarIdType The variable's underlying ID type.
*/
template <domain_space Domain, typename VarIdType>
template <domain_space Domain>
struct var_id_limits {
// Types
using var_id_type = VarIdType;
using var_id_type = default_var_id_type;

// Constexpr static values
constexpr static bool valid = false;
constexpr static const bool valid = false;
constexpr static const domain_space space = Domain;
};

Expand All @@ -49,16 +51,17 @@ struct var_id_limits {
* @tparam VarIdType The variable ID's type.
* @see adl::oct::var_id_limits<>
*/
template <typename VarIdType>
struct var_id_limits<domain_space::oct, VarIdType> {
template <>
struct var_id_limits<domain_space::oct> {
// Types
using var_id_type = VarIdType;
using var_id_type = default_var_id_type;
using counterpart_var_id_limits = var_id_limits<domain_space::octdiff>;

// Constexpr static values
constexpr static bool valid = true;
constexpr static const bool valid = true;
constexpr static const domain_space space = domain_space::oct;
constexpr static oct::domain_space counterpart_space = oct::domain_space::octdiff;
constexpr static const std::size_t max_variables = max_oct_variables<VarIdType>;
constexpr static const domain_space counterpart_space = oct::domain_space::octdiff;
constexpr static const std::size_t max_variables = max_oct_variables<var_id_type>;
constexpr static const var_id_type invalid_var_id = var_id_type(0);
constexpr static const var_id_type first_var_id = var_id_type(1);
constexpr static const var_id_type last_var_id = var_id_type(max_variables - 1);
Expand All @@ -67,6 +70,9 @@ struct var_id_limits<domain_space::oct, VarIdType> {
constexpr static const var_id_type rbegin_var_id = last_var_id;
constexpr static const var_id_type rend_var_id = 0;

constexpr static const var_id_type min_var_id_value = -last_var_id;
constexpr static const var_id_type max_var_id_value = end_var_id;

constexpr static const char *const base_var_name_format = "x%d";
constexpr static const char *const positive_var_name_format = "%s";
constexpr static const char *const negative_var_name_format = "-%s";
Expand All @@ -76,25 +82,29 @@ struct var_id_limits<domain_space::oct, VarIdType> {
* Specialization of `adl::oct::var_id_limits` for the octagonal-difference domain space.
* @tparam VarIdType The variable ID's type.
*/
template <typename VarIdType>
struct var_id_limits<domain_space::octdiff, VarIdType> {
template <>
struct var_id_limits<domain_space::octdiff> {
// Types
using var_id_type = VarIdType;
using var_id_type = default_var_id_type;
using counterpart_var_id_limits = var_id_limits<domain_space::oct>;

// Constexpr static values
constexpr static bool valid = true;
constexpr static oct::domain_space space = oct::domain_space::octdiff;
constexpr static oct::domain_space counterpart_space = oct::domain_space::oct;
constexpr static std::size_t max_variables = max_octdiff_variables<VarIdType>;
constexpr static var_id_type invalid_var_id = var_id_limits<domain_space::oct, VarIdType>::invalid_var_id;
constexpr static var_id_type first_var_id = var_id_limits<domain_space::oct, VarIdType>::first_var_id;
constexpr static var_id_type last_var_id = var_id_type(max_variables - 3);
constexpr static var_id_type begin_var_id = first_var_id;
constexpr static var_id_type end_var_id = var_id_type(last_var_id + 2);
constexpr static var_id_type rbegin_var_id = last_var_id;
constexpr static var_id_type rend_var_id = var_id_limits<domain_space::oct, VarIdType>::rend_var_id;

constexpr static const char *const base_var_name_format = var_id_limits<domain_space::oct, VarIdType>::base_var_name_format;
constexpr static const bool valid = true;
constexpr static const domain_space space = oct::domain_space::octdiff;
constexpr static const domain_space counterpart_space = oct::domain_space::oct;
constexpr static const std::size_t max_variables = max_octdiff_variables<var_id_type>;
constexpr static const var_id_type invalid_var_id = var_id_limits<domain_space::oct>::invalid_var_id;
constexpr static const var_id_type first_var_id = var_id_limits<domain_space::oct>::first_var_id;
constexpr static const var_id_type last_var_id = var_id_type(max_variables - 3);
constexpr static const var_id_type begin_var_id = first_var_id;
constexpr static const var_id_type end_var_id = var_id_type(last_var_id + 2);
constexpr static const var_id_type rbegin_var_id = last_var_id;
constexpr static const var_id_type rend_var_id = var_id_limits<domain_space::oct>::rend_var_id;

constexpr static const var_id_type min_var_id_value = 0;
constexpr static const var_id_type max_var_id_value = end_var_id;

constexpr static const char *const base_var_name_format = var_id_limits<domain_space::oct>::base_var_name_format;
constexpr static const char *const positive_var_name_format = "%s__pos";
constexpr static const char *const negative_var_name_format = "%s__neg";
};
Expand Down
Loading

0 comments on commit 1402e36

Please sign in to comment.