Keyple Util C++ Library 2.0.0
Reference Terminal Reader API for C++
KeypleAssert.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2021 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#pragma once
14
15#include <memory>
16#include <string>
17#include <vector>
18
19/* Util */
20#include "KeypleUtilExport.h"
22
23namespace keyple {
24namespace core {
25namespace util {
26
28
36public:
42 static Assert& getInstance();
43
53 template <typename T>
54 Assert& notNull(const std::shared_ptr<T> obj, const std::string& name)
55 {
56 if (obj == nullptr) {
57 throw IllegalArgumentException(ARGUMENT + name + IS_NULL);
58 }
59
60 return *this;
61 }
62
72 Assert& notEmpty(const std::string& obj, const std::string& name);
73
83 template<typename T>
84 Assert& notEmpty(const std::vector<T>& obj, const std::string& name)
85 {
86 if (obj.empty()) {
87 throw IllegalArgumentException(ARGUMENT + name + IS_EMPTY);
88 }
89
90 return *this;
91 }
92
102 Assert& notEmpty(const std::vector<uint8_t>& obj, const std::string& name);
103
113 Assert& isTrue(const bool condition, const std::string& name);
114
125 Assert& greaterOrEqual(const size_t number, const size_t minValue, const std::string& name);
126
137 Assert& isEqual(const size_t number, const size_t value, const std::string& name);
138
150 Assert& isInRange(const size_t number,
151 const size_t minValue,
152 const size_t maxValue,
153 const std::string& name);
154
165 Assert& isHexString(const std::string& hex, const std::string& name);
166
167private:
171 static const std::string ARGUMENT;
172 static const std::string CONDITION;
173 static const std::string HAS_A_VALUE;
174 static const std::string LESS_THAN;
175 static const std::string GREATER_THAN;
176 static const std::string IS_NULL;
177 static const std::string IS_EMPTY;
178 static const std::string IS_FALSE;
179 static const std::string IS_NOT_HEX;
180 static const std::string NOT_EQUAL_TO;
181 static const std::string CLOSING_BRACKET;
182
186 Assert();
187};
188
189}
190}
191}
#define KEYPLEUTIL_API
Assert & notNull(const std::shared_ptr< T > obj, const std::string &name)
Definition: KeypleAssert.h:54
Assert & notEmpty(const std::vector< T > &obj, const std::string &name)
Definition: KeypleAssert.h:84