Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* @file api.String.hpp |
3 |
|
|
* @author Sergey Baigudin, sergey@baigudin.software |
4 |
|
|
* @copyright 2017-2022, Sergey Baigudin, Baigudin Software |
5 |
|
|
*/ |
6 |
|
|
#ifndef API_STRING_HPP_ |
7 |
|
|
#define API_STRING_HPP_ |
8 |
|
|
|
9 |
|
|
#include "api.Collection.hpp" |
10 |
|
|
|
11 |
|
|
namespace eoos |
12 |
|
|
{ |
13 |
|
|
namespace api |
14 |
|
|
{ |
15 |
|
|
|
16 |
|
|
/** |
17 |
|
|
* @class String<T> |
18 |
|
|
* @brief String interface. |
19 |
|
|
* |
20 |
|
|
* @tparam T Data type of string characters. |
21 |
|
|
*/ |
22 |
|
|
template <typename T> |
23 |
|
|
class String : public Collection<T> |
24 |
|
|
{ |
25 |
|
|
|
26 |
|
|
public: |
27 |
|
|
|
28 |
|
|
/** |
29 |
|
|
* @brief Destructor. |
30 |
|
|
*/ |
31 |
|
|
virtual ~String() = 0; |
32 |
|
|
|
33 |
|
|
/** |
34 |
|
|
* @brief Copies a passed string into this string. |
35 |
|
|
* |
36 |
|
|
* @note A passed string must be copied to an internal containing string of |
37 |
|
|
* a implemented class so that the passed string might be invalidated after |
38 |
|
|
* the function called. |
39 |
|
|
* |
40 |
|
|
* @note If implementation of the interface is static, which means it has |
41 |
|
|
* certain number of elements to contain a string of characters, and a passed |
42 |
|
|
* string more than the implementation can physically contain, the passed string |
43 |
|
|
* will be cropped to max available length of such implementation. Return value |
44 |
|
|
* will be also true. |
45 |
|
|
* |
46 |
|
|
* @param string A string object interface to be copied. |
47 |
|
|
* @return True if a passed string has been copied successfully. |
48 |
|
|
*/ |
49 |
|
|
virtual bool_t copy(String<T> const& string) = 0; |
50 |
|
|
|
51 |
|
|
/** |
52 |
|
|
* @brief Concatenates a passed string to this string. |
53 |
|
|
* |
54 |
|
|
* @note A passed string must be appended to an internal containing string of |
55 |
|
|
* a realizing class so that the passed string might be invalidated after the function called. |
56 |
|
|
* |
57 |
|
|
* @param string A string object interface to be appended. |
58 |
|
|
* @return True if a passed string has been appended successfully. |
59 |
|
|
*/ |
60 |
|
|
virtual bool_t concatenate(String<T> const& string) = 0; |
61 |
|
|
|
62 |
|
|
/** |
63 |
|
|
* @brief Compares this string with a passed string lexicographically. |
64 |
|
|
* |
65 |
|
|
* @param string A string object interface to be compared with. |
66 |
|
|
* @return true if this string equals to a given string. |
67 |
|
|
*/ |
68 |
|
|
virtual bool_t isEqualTo(String<T> const& string) const = 0; |
69 |
|
|
|
70 |
|
|
/** |
71 |
|
|
* @brief Returns pointer to the first character of containing string. |
72 |
|
|
* |
73 |
|
|
* @note Be careful, some action with the object might relocate internal buffer |
74 |
|
|
* that contains characters. By this reason, a returned address will be actual |
75 |
|
|
* until you do not call a non-constant function of this class for an object. |
76 |
|
|
* |
77 |
|
|
* @return First character of containing string characters, or NULLPTR if an error occurred. |
78 |
|
|
*/ |
79 |
|
|
virtual T const* getChar() const = 0; |
80 |
|
|
|
81 |
|
|
}; |
82 |
|
|
|
83 |
|
|
template <typename T> ///< SCA MISRA-C++:2008 Defected Rule 7-3-1 |
84 |
|
632 |
inline String<T>::~String() {} |
85 |
|
|
|
86 |
|
|
} // namespace api |
87 |
|
|
} // namespace eoos |
88 |
|
|
#endif // API_STRING_HPP_ |
89 |
|
|
|