Skip to content

Commit

Permalink
Finish static assert adding
Browse files Browse the repository at this point in the history
  • Loading branch information
mrognor committed Dec 15, 2024
1 parent 8e2e948 commit a97d08f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
46 changes: 44 additions & 2 deletions Source/Vault.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ namespace mvlt
template <class T>
VaultOperationResult Vault::AddUniqueKey(const std::string& key) noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
AddUniqueKey<std::string>(\"Key\")");

return AddKey(key, T(), true, true, {[&](std::size_t counter, const VaultRecordRef&) -> T{ return T(); }});
}

Expand All @@ -583,6 +587,10 @@ namespace mvlt
template <class T>
VaultOperationResult Vault::UpdateKey(const std::string& key, const T& defaultKeyValue) noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
UpdateKey<std::string>(\"Key\", \"Value\") or UpdateKey(\"Key\", std::string(\"Value\"))");

VaultOperationResult res;
res.Key = key;
res.RequestedType = typeid(defaultKeyValue);
Expand Down Expand Up @@ -626,6 +634,8 @@ namespace mvlt
template <class T>
VaultOperationResult Vault::GetKeyValue(const std::string& key, T& defaultKeyValue) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value.");

VaultOperationResult res;
res.Key = key;
res.RequestedType = typeid(T);
Expand Down Expand Up @@ -676,7 +686,7 @@ namespace mvlt
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
AddKey<std::string>(\"Key\", \"Value\") or AddKey(\"Key\", std::string(\"Value\"))");
GetRecord<std::string>(\"Key\", \"Value\") or GetRecord(\"Key\", std::string(\"Value\"))");

// Fill res info known at start
VaultOperationResult res;
Expand Down Expand Up @@ -731,7 +741,7 @@ namespace mvlt
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
AddKey<std::string>(\"Key\", \"Value\") or AddKey(\"Key\", std::string(\"Value\"))");
GetRecords<std::string>(\"Key\", \"Value\") or GetRecords(\"Key\", std::string(\"Value\"))");

// Fill res info known at start
VaultOperationResult res;
Expand Down Expand Up @@ -790,34 +800,54 @@ namespace mvlt
VaultOperationResult Vault::RequestEqual(const std::string& key, const T& keyValue, VaultRecordSet& vaultRecordSet,
const std::size_t& amountOfRecords, const std::function<bool(const VaultRecordRef&)>& requestPredicat) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RequestEqual<std::string>(\"Key\", \"Value\") or RequestEqual(\"Key\", std::string(\"Value\"))");

return RequestRecords(VaultRequestType::Equal, key, keyValue, keyValue, vaultRecordSet, false, false, amountOfRecords, requestPredicat);
}

template <class T>
VaultOperationResult Vault::RequestGreater(const std::string& key, const T& keyValue, VaultRecordSet& vaultRecordSet,
const std::size_t& amountOfRecords, const std::function<bool(const VaultRecordRef&)>& requestPredicat) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RequestGreater<std::string>(\"Key\", \"Value\") or RequestGreater(\"Key\", std::string(\"Value\"))");

return RequestRecords(VaultRequestType::Greater, key, keyValue, keyValue, vaultRecordSet, false, false, amountOfRecords, requestPredicat);
}

template <class T>
VaultOperationResult Vault::RequestGreaterOrEqual(const std::string& key, const T& keyValue, VaultRecordSet& vaultRecordSet,
const std::size_t& amountOfRecords, const std::function<bool(const VaultRecordRef&)>& requestPredicat) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RequestGreaterOrEqual<std::string>(\"Key\", \"Value\") or RequestGreaterOrEqual(\"Key\", std::string(\"Value\"))");

return RequestRecords(VaultRequestType::GreaterOrEqual, key, keyValue, keyValue, vaultRecordSet, false, false, amountOfRecords, requestPredicat);
}

template <class T>
VaultOperationResult Vault::RequestLess(const std::string& key, const T& keyValue, VaultRecordSet& vaultRecordSet,
const std::size_t& amountOfRecords, const std::function<bool(const VaultRecordRef&)>& requestPredicat) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RequestLess<std::string>(\"Key\", \"Value\") or RequestLess(\"Key\", std::string(\"Value\"))");

return RequestRecords(VaultRequestType::Less, key, keyValue, keyValue, vaultRecordSet, false, false, amountOfRecords, requestPredicat);
}

template <class T>
VaultOperationResult Vault::RequestLessOrEqual(const std::string& key, const T& keyValue, VaultRecordSet& vaultRecordSet,
const std::size_t& amountOfRecords, const std::function<bool(const VaultRecordRef&)>& requestPredicat) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RequestLessOrEqual<std::string>(\"Key\", \"Value\") or RequestLessOrEqual(\"Key\", std::string(\"Value\"))");

return RequestRecords(VaultRequestType::LessOrEqual, key, keyValue, keyValue, vaultRecordSet, false, false, amountOfRecords, requestPredicat);
}

Expand All @@ -826,6 +856,10 @@ namespace mvlt
const T& endKeyValue, VaultRecordSet& vaultRecordSet, const bool& isIncludeBeginKeyValue,
const bool& isIncludeEndKeyValue, const std::size_t& amountOfRecords, const std::function<bool(const VaultRecordRef&)>& requestPredicat) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RequestInterval<std::string>(\"Key\", \"Value\") or RequestInterval(\"Key\", std::string(\"Value\"))");

return RequestRecords(VaultRequestType::Interval, key, beginKeyValue,
endKeyValue, vaultRecordSet, isIncludeBeginKeyValue, isIncludeEndKeyValue,
amountOfRecords, requestPredicat);
Expand Down Expand Up @@ -889,6 +923,10 @@ namespace mvlt
template <class T>
VaultOperationResult Vault::EraseRecord(const std::string& key, const T& keyValue) noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
EraseRecord<std::string>(\"Key\", \"Value\") or EraseRecord(\"Key\", std::string(\"Value\"))");

// Fill res info known at start
VaultOperationResult res;
res.Key = key;
Expand Down Expand Up @@ -953,6 +991,10 @@ namespace mvlt
template <class T>
VaultOperationResult Vault::EraseRecords(const std::string& key, const T& keyValue, const std::size_t& amountOfRecords) noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
EraseRecords<std::string>(\"Key\", \"Value\") or EraseRecords(\"Key\", std::string(\"Value\"))");

// Fill res info known at start
VaultOperationResult res;
res.Key = key;
Expand Down
2 changes: 1 addition & 1 deletion Source/VaultParamInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace mvlt
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
AddKey<std::string>(\"Key\", \"Value\") or AddKey(\"Key\", std::string(\"Value\"))");
CreateRecord({{\"Key\", std::string(\"Value\")}});");

SetDataToRefFunc = [=](const std::string& key, VaultRecordRef& refToSetData)
{
Expand Down
8 changes: 8 additions & 0 deletions Source/VaultRecordRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace mvlt
template <class T>
VaultOperationResult VaultRecordRef::SetData(const std::string& key, const T& data) noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
SetData<std::string>(\"Key\", \"Value\") or SetData(\"Key\", std::string(\"Value\"))");

VaultOperationResult res;
res.Key = key;
res.RequestedType = typeid(T);
Expand Down Expand Up @@ -38,6 +42,10 @@ namespace mvlt
template <class T>
VaultOperationResult VaultRecordRef::GetData(const std::string& key, T& data) const noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
GetData<std::string>(\"Key\", \"Value\") or GetData(\"Key\", std::string(\"Value\"))");

// Fill res info known at start
VaultOperationResult res;
res.Key = key;
Expand Down
8 changes: 8 additions & 0 deletions Source/VaultRecordSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ namespace mvlt
template <class T>
VaultOperationResult VaultRecordSet::RemoveRecord(const std::string& key, const T& keyValue) noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RemoveRecord<std::string>(\"Key\", \"Value\") or RemoveRecord(\"Key\", std::string(\"Value\"))");

VaultOperationResult res;

if (GetIsParentVaultValid())
Expand All @@ -200,6 +204,10 @@ namespace mvlt
template <class T>
VaultOperationResult VaultRecordSet::RemoveRecords(const std::string& key, const T& keyValue, const std::size_t& amountOfRecords) noexcept
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
RemoveRecords<std::string>(\"Key\", \"Value\") or RemoveRecords(\"Key\", std::string(\"Value\"))");

VaultOperationResult res;

if (GetIsParentVaultValid())
Expand Down
5 changes: 5 additions & 0 deletions Source/VaultRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace mvlt
template <class T>
VaultRequest<Type>::VaultRequest(const std::string& key, const T& keyValue, std::function<bool(const VaultRecordRef&)> requestPredicat) : Key(key), RequestPredicat(requestPredicat)
{
static_assert(!std::is_array<T>::value, "It is not possible to use a c array as a key value. \n\
If you want to use a string as a key, you must specialize the function with a string. Like this: \n\
Less<std::string>(\"Key\", \"Value\") or Greater(\"Key\", std::string(\"Value\")). \n\
This works with the following classes: Less, LessOrEqual, Equal, GreaterOrEqual, Greater.");

DataPtr = static_cast<void*>(new T(keyValue));

// Set Request func
Expand Down

0 comments on commit a97d08f

Please sign in to comment.