Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Oct 21, 2023
1 parent 90428ca commit c733287
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Makefile.local
merged_api.yaml
tests/results
Makefile.local
log_build.txt
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_library(${PROJECT_NAME}_objs OBJECT
)
target_include_directories(${PROJECT_NAME}_objs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver-core userver-postgresql)
# target_compile_options(${PROJECT_NAME}_objs PRIVATE -Wfatal-errors)


# The Service
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ gen:
$(MAKE) gen-sources
$(MAKE) gen-all-headers

.PHONY: build-log
build-log:
$(MAKE) -s test-debug > log_build.txt 2>&1

# # Internal hidden targets that are used only in docker environment
# --in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-%
# @sed -i 's/config_vars.yaml/config_vars.docker.yaml/g' /home/user/.local/etc/timetable_vsu_backend/static_config.yaml
Expand Down
70 changes: 15 additions & 55 deletions src/openapi/base/traits/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,93 +13,53 @@ concept HasMin = requires
{
{
T::kMin
}
->std::convertible_to<utils::ConstexprOptional<std::int64_t>>;
};
};

template <typename T>
concept HasMax = requires
{
{
T::kMax
}
->std::convertible_to<utils::ConstexprOptional<std::int64_t>>;
};
};

template <typename T>
concept HasUniqueItems = requires
{
{
T::kUniqueItems
}
->std::convertible_to<utils::ConstexprOptional<bool>>;
};
};

template <typename T>
concept HasNotMin = !HasMin<T>;

template <typename T>
concept HasNotMax = !HasMax<T>;

template <typename T>
concept HasNotUniqueItems = !HasUniqueItems<T>;
} // namespace checks

namespace detail
{
template <checks::HasMin T>
constexpr auto _getMin()
{
return T::kMin;
}

template <checks::HasNotMin T>
constexpr auto _getMin()
{
return utils::ConstexprOptional<std::int64_t>{utils::kNull};
}

template <checks::HasMax T>
constexpr auto _getMax()
{
return T::kMax;
}

template <checks::HasNotMax T>
constexpr auto _getMax()
{
return utils::ConstexprOptional<std::int64_t>{utils::kNull};
}

template <checks::HasUniqueItems T>
constexpr auto _getUniqueItems()
{
return T::kUniqueItems;
}

template <checks::HasNotUniqueItems T>
constexpr auto _getUniqueItems()
{
return utils::ConstexprOptional<bool>{utils::kNull};
}
} // namespace detail

namespace traits
{
template <typename T>
constexpr utils::ConstexprOptional<std::int64_t> GetMin()
{
return detail::_getMin<T>();
if constexpr (checks::HasMin<T>){
return T::kMin;
}
else return utils::kNull;
}
template <typename T>
constexpr utils::ConstexprOptional<std::int64_t> GetMax()
{
return detail::_getMax<T>();
if constexpr (checks::HasMax<T>){
return T::kMax;
}
else return utils::kNull;
}
template <typename T>
constexpr utils::ConstexprOptional<bool> GetUniqueItems()
{
return detail::_getUniqueItems<T>();
if constexpr (checks::HasUniqueItems<T>){
return T::kUniqueItems;
}
else return utils::kNull;
}

template <typename Traits>
Expand Down
26 changes: 5 additions & 21 deletions src/openapi/base/traits/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,20 @@ concept HasUseNullOnFail = requires
{
{
T::kUseNullOnFail
}
->std::convertible_to<utils::ConstexprOptional<bool>>;
};
};

} // namespace checks

namespace detail
{
template <typename T>
requires checks::HasUseNullOnFail<T> constexpr utils::ConstexprOptional<bool>
_getUseNullOnFail()
{
return T::kUseNullOnFail;
}

template <typename T>
requires(!checks::HasUseNullOnFail<T>) constexpr utils::ConstexprOptional<
bool> _getUseNullOnFail()
{
return utils::kNull;
}

} // namespace detail

namespace traits
{
template <typename T>
constexpr utils::ConstexprOptional<bool> GetUseNullOnFail()
{
return detail::_getUseNullOnFail<T>();
if constexpr (checks::HasUseNullOnFail<T>){
return T::kUseNullOnFail;
}
else return utils::kNull;
}

template <typename Traits>
Expand Down
31 changes: 5 additions & 26 deletions src/openapi/base/traits/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,21 @@ namespace checks
template <typename T>
concept HasPattern = requires
{
{
decltype(T::kPattern)::kSize
}
->std::convertible_to<std::size_t>;
requires std::is_same_v<
utils::ConstexprString<decltype(T::kPattern)::kSize>,
std::remove_cv_t<decltype(T::kPattern)>>;
{
T::kPattern
}
->std::convertible_to<utils::ConstexprString<decltype(T::kPattern)::kSize>>;
};
};
} // namespace checks

namespace detail
{
template <typename T>
requires checks::HasPattern<T> constexpr auto _getPattern()
{
return T::kPattern;
}

template <typename T>
requires(!checks::HasPattern<T>) constexpr auto _getPattern()
{
using Type = utils::ConstexprString<1>;
return Type{""};
}
} // namespace detail

namespace traits
{
template <typename T>
constexpr auto GetPattern()
{
return detail::_getPattern<T>();
if constexpr (checks::HasPattern<T>){
return T::kPattern;
}
else return utils::kEmptyString;
}

template <typename Traits>
Expand Down
4 changes: 4 additions & 0 deletions src/utils/constexpr_optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct ConstexprOptional
using value_type = T;
T value_;
bool has_value_;
constexpr ConstexprOptional() noexcept
: value_(T{}), has_value_(false)
{
}
constexpr ConstexprOptional(const T& value) noexcept
: value_(value), has_value_(true)
{
Expand Down
3 changes: 3 additions & 0 deletions src/utils/constexpr_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ struct ConstexprString
return string == lhs;
}
};

constexpr ConstexprString<1> kEmptyString{};

template <std::size_t n>
ConstexprString(char const (&)[n]) -> ConstexprString<n>;

Expand Down
2 changes: 1 addition & 1 deletion utests/openapi/json/parse/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

using namespace openapi;

UTEST(Openapi_Json_Parse, BasicUuid)
UTEST(Openapi_Json_Parse, BasicDatetime)
{
//2011-08-12T20:17:46.384Z

Expand Down

0 comments on commit c733287

Please sign in to comment.