Class IpcMessage
Defined in File ipc_message.hpp
Class Documentation
-
class IpcMessage
The symbol , is per default the separator.
A valid entry is an arbitrary string which does not contain the separator symbol, otherwise, if it contains the separator symbol it is defined as a invalid entry. A valid entry can contain none or more characters.
A message is a concatination of valid entries separated by the separator. A message is defined as valid if all entries contained in that message are valid and it ends with the separator or it is empty, otherwise it is defined as invalid.
Public Functions
-
IpcMessage() noexcept = default
Creates an empty and valid IPC channel message.
-
IpcMessage(const std::initializer_list<std::string> &msg) noexcept
Creates a separator separated string. If one element contains a separator symbol the IpcMessage becomes invalid and returns false on isValid().
- Parameters:
msg – [in] array of strings to combine in a message
-
IpcMessage(const std::string &msg) noexcept
Takes a separator separated string and interprets it as a IpcMessage. In this case the IpcMessage can only become invalid if it is not empty and does not end with the separator.
- Parameters:
separator – [in] separated string for a message
-
template<typename T>
IpcMessage &operator<<(const T &entry) noexcept Adds a new entry to the IpcMessage, if the entry is invalid no entry is added and the IpcMessage becomes invalid.
- Parameters:
entry – [in] Datatype which is convertable to string via std::to_string
-
uint32_t getNumberOfElements() const noexcept
Returns the number of entries stored in IpcMessage. If the message is invalid the return value is undefined.
- Returns:
number of entries in messaage
-
std::string getElementAtIndex(const uint32_t index) const noexcept
Returns the entry at position f_index. If f_index is larger then the sum of the entries stored in IpcMessage it returns std::string()
- Parameters:
index – [in] desired entry position
- Returns:
If the element exists it returns the element at f_index otherwise an empty string
-
bool isValidEntry(const std::string &entry) const noexcept
returns if an entry is valid. Non valid entries are containing at least one separator
- Parameters:
entry – [in] sstring to check
- Returns:
true = if it is a valid entry otherwise false
-
bool isValid() const noexcept
check if the message is valid
- Returns:
If one element in the CTor initializer_list was invalid it returns false, otherwise true.
-
std::string getMessage() const noexcept
The message is casted to the actual separator separated string If the message is invalid the return value is undefined.
- Returns:
the current message as separator separated string
-
void setMessage(const std::string &msg) noexcept
Takes a separator separated string and interprets it as a IpcMessage. In this case the IpcMessage can only become invalid if it is not empty and does not end with the separator. All the entries that were stored previously in the IpcMessage will be cleared after a call to setMessage.
- Parameters:
separator – [in] separated string for the message
-
void clearMessage() noexcept
Clears the message. After a call to clearMessage() the.
-
template<typename T>
void addEntry(const T &entry) noexcept Adds a new entry to the IpcMessage, if the entry is invalid no entry is added and the IpcMessage becomes invalid.
- Template Parameters:
Datatype – which is convertable to string via std::stringstream
- Parameters:
entry – [in] to add to the message
-
bool operator==(const IpcMessage &rhs) const noexcept
Compares two IpcMessages to be equal.
- Parameters:
rhs – IpcMessage to compare with
-
IpcMessage() noexcept = default