20#include <boost/functional/hash/hash.hpp>
62 result.
m_raw_name.assign(std::move(src_moved));
177 using flow::util::in_closed_range;
193 bool prev_is_sep =
false;
197 if ((!is_sep) && (!isalnum(ch)))
226 constexpr char SEPARATOR_ALT =
'/';
228 "The real separator and the alt must be different characters.");
229 constexpr const char SEPS[] = { SEPARATOR_ALT,
S_SEPARATOR,
'\0' };
243 string orig_backup_or_empty_if_unchanged;
246 const auto undo_changes_pre_return_false_func = [&]()
248 if (!orig_backup_or_empty_if_unchanged.empty())
251 m_raw_name = std::move(orig_backup_or_empty_if_unchanged);
256 const size_t n =
size();
258 for (
size_t in_pos = 0; in_pos != n;
267 undo_changes_pre_return_false_func();
273 bool is_last = in_pos == n - 1;
274 const bool is_sep = (ch ==
S_SEPARATOR) || (ch == SEPARATOR_ALT);
277 if ((!is_sep) && (!isalnum(ch)))
279 undo_changes_pre_return_false_func();
296 in_pos =
m_raw_name.find_first_not_of(SEPS, in_pos + 1);
297 if (in_pos == string::npos)
305 assert(in_pos != (n - 1));
318 if (orig_backup_or_empty_if_unchanged.empty() && (!is_last))
321 orig_backup_or_empty_if_unchanged =
m_raw_name;
339 assert(!resource_type.
empty());
346 name /= resource_type;
356 if (val.
str().empty())
361 return os << val.
str().size() <<
'|' << val.
str();
375 return val1.
str() == val2.
str();
409 return val1.
str() < val2.
str();
417 return hash<string>()(val.
str());
String-wrapping abstraction representing a name uniquely distinguishing a kernel-persistent entity fr...
bool sanitized() const
Returns true if and only if the contained name/fragment is sanitized according to length,...
const char * native_str() const
Returns (sans copying) pointer to NUL-terminated wrapped name string, suitable to pass into sys calls...
Shared_name & operator+=(const Shared_name &src_to_append)
Appends the given other Shared_name.
Shared_name()
Constructs empty() name.
static const Shared_name S_SENTINEL
A Shared_name fragment, with no S_SEPARATOR characters inside, that represents a path component that ...
static Shared_name ct(const Source &src)
Copy-constructs from a char-sequence container (including string, util::String_view,...
static const Shared_name S_RESOURCE_TYPE_ID_SHM
Relative-folder fragment (no separators) identifying the resource type for: SHM pools.
std::string m_raw_name
The name or name fragment; see str().
static const Shared_name S_RESOURCE_TYPE_ID_MUTEX
Relative-folder fragment (no separators) identifying the resource type for: boost....
static const Shared_name S_EMPTY
A (default-cted) Shared_name. May be useful for functions returning const Shared_name&.
static const char S_SEPARATOR
Character we use, by convention, to separate conceptual folders within str().
bool has_trailing_separator() const
Returns true if and only if !this->empty(), and str() ends with the S_SEPARATOR character.
void clear()
Makes it so empty() == true.
bool empty() const
Returns true if and only if str().empty() == true.
Shared_name & operator/=(const Shared_name &src_to_append)
Appends a folder separator followed by the given other Shared_name.
static const Shared_name S_1ST_OR_ONLY
A Shared_name fragment, with no S_SEPARATOR characters inside, that represents a path component that ...
bool absolute() const
Returns true if and only if the first character is S_SEPARATOR.
Shared_name & operator=(const Shared_name &src)
Copy-assigns from an existing Shared_name.
bool sanitize()
Best-effort attempt to turn sanitized() from false to true, unless it is already true; returns the fi...
const std::string & str() const
Returns (sans copying) ref to immutable entire wrapped name string, suitable to pass into sys calls w...
static const Shared_name S_ROOT_MAGIC
A Shared_name fragment, with no S_SEPARATOR characters inside, to be used in any Shared_name maintain...
size_t size() const
Returns str().size().
static const size_t S_MAX_LENGTH
Max value of size() such that, if str() used to name a supported shared resource, sys call safely won...
util::Shared_name Shared_name
Convenience alias for the commonly used type util::Shared_name.
Flow-IPC module containing miscellaneous general-use facilities that ubiquitously used by ~all Flow-I...
std::ostream & operator<<(std::ostream &os, const Native_handle &val)
Prints string representation of the given Native_handle to the given ostream.
bool operator<(Native_handle val1, Native_handle val2)
Returns a less-than comparison of two Native_handle objects, with the usual total ordering guarantees...
Shared_name build_conventional_non_session_based_shared_name(const Shared_name &resource_type)
Builds an absolute name according to the path convention explained in Shared_name class doc header; t...
bool operator==(util::String_view val1, const Shared_name &val2)
Returns true if and only if string(val1) == val2.str().
void swap(Shared_name &val1, Shared_name &val2)
Swaps two objects.
Shared_name operator/(const Shared_name &src1, const char *raw_src2)
Returns new object equal to Shared_name(src1) /= raw_src2.
bool operator!=(Native_handle val1, Native_handle val2)
Negation of similar ==.
size_t hash_value(Native_handle val)
Hasher of Native_handle for boost.unordered et al.
std::istream & operator>>(std::istream &is, Shared_name &val)
Reads Shared_name from the given istream; equivalent to reading string into Shared_name::str().
bool operator==(Native_handle val1, Native_handle val2)
Returns true if and only if the two Native_handle objects are the same underlying handle.
flow::util::String_view String_view
Short-hand for Flow's String_view.
Shared_name operator+(const Shared_name &src1, const char *raw_src2)
Returns new object equal to Shared_name(src1) += raw_src2.