This repository has been archived by the owner on Jan 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Bounded string
justinemclevy edited this page Jan 23, 2014
·
2 revisions
This is an extension of std::string, forcing a minimum size of the string must be specified during the construction. The specification of the maximum size of the string is optional.
#include "maidsafe/common/bounded_string.h"
#include "maidsafe/common/utils.h"
typedef detail::BoundedString<1> NonEmptyString;
typedef detail::BoundedString<64, 64> Identity;
int main() {
NonEmptyString empty_string; // expect compilation error
NonEmptyString non_empty_string("this is a non_empty_string");
Identity too_short("this is too short"); // expect compilation error
Identity too_long(RandomString(128)); // expect compilation error
Identity identity(RandomString(64));
std::cout << ideneity.string() << std::endl;
return 0;
}
class BoundedString {
public:
BoundedString();
explicit BoundedString(StringType string);
BoundedString(const BoundedString& other);
BoundedString(BoundedString&& other) MAIDSAFE_NOEXCEPT;
BoundedString& operator=(BoundedString other) MAIDSAFE_NOEXCEPT;
BoundedString& operator+=(const BoundedString& other);
template<size_t other_min, size_t other_max, typename OtherStringType>
explicit BoundedString(BoundedString<other_min, other_max, OtherStringType> other);
template<size_t other_min, size_t other_max, typename OtherStringType>
BoundedString& operator=(BoundedString<other_min, other_max, OtherStringType> other);
template<size_t other_min, size_t other_max, typename OtherStringType>
BoundedString& operator+=(const BoundedString<other_min, other_max, OtherStringType>& other);
const StringType& string() const;
bool IsInitialised() const;
friend void swap(BoundedString& first, BoundedString& second) MAIDSAFE_NOEXCEPT;
template<size_t other_min, size_t other_max, typename OtherStringType> friend class BoundedString;
private:
....
}
MaidSafe Common Library
MaidSafe Project
- MaidSafe
- MaidSafe-API
- MaidSafe-Common
- MaidSafe-Passport
- MaidSafe-RUDP
- MaidSafe-Routing
- MaidSafe-Encrypt
- MaidSafe-Drive
- MaidSafe-Network-Filesystem
- MaidSafe-Vault
- MaidSafe-Vault-Manager
MaidSafe Papers