NDEVR
API Documentation
StringStream< t_type >

Logic for reading or writing to a string or a user friendly, TranslatedString. More...

Inheritance diagram for StringStream< t_type >:
[legend]

Static Public Member Functions

static void fromString (const StringView &string, t_type &value)
 Logic for converting an object from an NDEVR API String allowing it to be used automatically with getAs<>(), Files, GenericOptions, and various other data structures.
static const char * getValidRegex ()
 Optionally specified to allow the software to do a check on user or file input to ensure that fromString will return a valid result or to limit user live input.
static void toDisplayString (const t_type &value, TranslatedString &string)
 Logic for converting an object to an NDEVR API translated, user facing string.
static void toString (const t_type &value, StringAllocatingView &string)
 Logic for converting an object to an NDEVR API String allowing it to be used automatically with the String constructor, GenericOptions, Scanners, and various other data structures.

Detailed Description

template<class t_type>
class StringStream< t_type >

Logic for reading or writing to a string or a user friendly, TranslatedString.


For example, to implement a given class or enum so that it can be cast to and from a string, or as a displayed to the end-user, you might add something similar to a CPP file.

Example Code For automatic conversion from another string class:

template<> void StringStream<QString>::fromString(const String& string, QString& value)
{
if (string.size() > 0)
value = QString::fromUtf8(string.c_str());
else
value.clear();
}
template<> void StringStream<QString>::toString(const QString& value, StringAllocatingView& string)
{
string.addAll(value.toUtf8().constData());
}
//No need to override toDisplayString as no custom way to show this data to the user
This class is like a string view, but may optionally store the data internally Useful if the return t...
Definition String.h:1278
static void fromString(const StringView &string, t_type &value)
Logic for converting an object from an NDEVR API String allowing it to be used automatically with get...
static void toString(const t_type &value, StringAllocatingView &string)
Logic for converting an object to an NDEVR API String allowing it to be used automatically with the S...
The core String class for the NDEVR API.
Definition String.h:95

Example Code For automatic conversion from a non-trivial structure

template<> void StringStream<KeyEvent>::fromString(const StringView& string, KeyEvent& value)
{
if (string.size() == 0)
value = KeyEvent();
else
{
Buffer<String> parts = string.splitString(cast<char>(29));
if (parts.size() == 3)
{
value.key_type = cast<KeyEvent::KEY>(parts[0].getAs<uint04>());
value.key_modifier = parts[1].getAs<uint01>();
value.event_type = cast<KeyEvent::KeyEentType>(parts[2].getAs<uint04>());
}
}
}
template<> void StringStream<KeyEvent>::toString(const KeyEvent& value, StringAllocatingView& string)
{
StringStream<uint04>::toString(cast<uint04>(value.key_type), string);
string += cast<char>(29);
StringStream<uint01>::toString(value.key_modifier, string);
string += cast<char>(29);
StringStream<uint04>::toString(cast<uint04>(value.event_type), string);
}
template<> void StringStream<KeyEvent>::toDisplayString(const KeyEvent& value, TranslatedString& translated_string)
{
String string;
if (value.key_modifier & KeyEvent::e_shift && value.key_type != KeyEvent::LIB_VK_SHIFT)
string += _t("SHIFT").translation()+"+";
if (value.key_modifier & KeyEvent::e_ctrl && value.key_type != KeyEvent::LIB_VK_RCONTROL && value.key_type != KeyEvent::LIB_VK_LCONTROL)
string += _t("CTRL").translation() + "+";
if (value.key_modifier & KeyEvent::e_function)
string += _t("FUNCTION").translation() + "+";
if (value.key_modifier & KeyEvent::e_alt && value.key_type != KeyEvent::LIB_VK_MENU)
string += _t("ALT").translation() + "+";
char char_val = value.toChar();
switch(char_val)
{
case '\n':
case ' ':
{
switch (value.key_type)
{
case KeyEvent::VK_KEY_F1: string += "F1"; break;
case KeyEvent::VK_KEY_F2: string += "F2"; break;
case KeyEvent::VK_KEY_F3: string += "F3"; break;
case KeyEvent::VK_KEY_F4: string += "F4"; break;
case KeyEvent::VK_KEY_F5: string += "F5"; break;
case KeyEvent::VK_KEY_F6: string += "F6"; break;
case KeyEvent::VK_KEY_F7: string += "F7"; break;
case KeyEvent::VK_KEY_F8: string += "F8"; break;
case KeyEvent::VK_KEY_F9: string += "F9"; break;
case KeyEvent::VK_KEY_F10: string += "F10"; break;
case KeyEvent::VK_KEY_F11: string += "F11"; break;
case KeyEvent::VK_KEY_F12: string += "F12"; break;
case KeyEvent::VK_KEY_F13: string += "F13"; break;
case KeyEvent::VK_KEY_F14: string += "F14"; break;
case KeyEvent::VK_KEY_F15: string += "F15"; break;
case KeyEvent::VK_KEY_F16: string += "F16"; break;
case KeyEvent::VK_KEY_F17: string += "F17"; break;
case KeyEvent::VK_KEY_F18: string += "F18"; break;
case KeyEvent::VK_KEY_F19: string += "F19"; break;
case KeyEvent::VK_KEY_F20: string += "F20"; break;
case KeyEvent::VK_KEY_F21: string += "F21"; break;
case KeyEvent::VK_KEY_F22: string += "F22"; break;
case KeyEvent::VK_KEY_F23: string += "F23"; break;
case KeyEvent::VK_KEY_F24: string += "F24"; break;
case KeyEvent::LIB_VK_META: string += "META"; break;
case KeyEvent::LIB_VK_SHIFT: string += "SHIFT"; break;
case KeyEvent::LIB_VK_MENU: string += "ALT"; break;
case KeyEvent::LIB_VK_RCONTROL: string += "RCTRL"; break;
case KeyEvent::LIB_VK_LCONTROL: string += "LCTRL"; break;
case KeyEvent::LIB_VK_SPACE: string += "SPACE"; break;
case KeyEvent::LIB_VK_ESCAPE: string += "ESC"; break;
case KeyEvent::LIB_VK_DELETE: string += "DEL"; break;
case KeyEvent::LIB_VK_RETURN: string += "ENTER"; break;
case KeyEvent::LIB_VK_EXECUTE: string += "EXE"; break;
case KeyEvent::LIB_VK_BUTTON_A: string += "A"; break;
case KeyEvent::LIB_VK_BUTTON_B: string += "B"; break;
case KeyEvent::LIB_VK_BUTTON_X: string += "X"; break;
case KeyEvent::LIB_VK_BUTTON_Y: string += "Y"; break;
case KeyEvent::LIB_VK_BUTTON_L1: string += "L1"; break;
case KeyEvent::LIB_VK_BUTTON_R1: string += "R1"; break;
case KeyEvent::LIB_VK_BUTTON_SELECT: string += "SELECT"; break;
case KeyEvent::LIB_VK_BUTTON_START: string += "START"; break;
case KeyEvent::LIB_VK_BUTTON_MODE: string += "MODE"; break;
case KeyEvent::LIB_VK_BUTTON_THUMBL: string += "TL"; break;
case KeyEvent::LIB_VK_BUTTON_THUMBR: string += "TR"; break;
case KeyEvent::LIB_VK_VOLUME_UP: string += "VOL+"; break;
case KeyEvent::LIB_VK_VOLUME_DOWN: string += "VOL-"; break;
default:
string += "("+String(cast<uint04>(value.key_type))+")";
break;
}
} break;
default:
string += cast<char>(toupper(value.toChar()));
break;
}
translated_string = TranslatedString(string);
}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Buffer< t_other_type, t_other_memory_manager > getAs() const
Gets a copy of this buffer, with filled objects t_other_type, where all objects are created using the...
Definition Buffer.hpp:176
Describes a user key press event used to trigger behavior in the NDEVR API.
Definition Event.h:49
uint01 key_modifier
Bitmask of active KeyModifier flags during this event.
Definition Event.h:291
@ e_shift
The Shift key modifier.
Definition Event.h:264
@ e_ctrl
The Control key modifier.
Definition Event.h:265
@ e_alt
The Alt key modifier.
Definition Event.h:267
@ e_function
The Function key modifier.
Definition Event.h:266
KeyEentType event_type
The type of key action (pressed, released, or unspecified).
Definition Event.h:292
KEY key_type
The virtual key code associated with this event.
Definition Event.h:290
static void toDisplayString(const t_type &value, TranslatedString &string)
Logic for converting an object to an NDEVR API translated, user facing string.
The core String View class for the NDEVR API.
Definition StringView.h:58
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408

Example code for auomatic conversion to enums:

template<> void
{
switch (string.hashUpper())
{
case String::hash("DEFAULT"): value = CompressionMode::e_default; break;
case String::hash("BEST"): value = CompressionMode::e_best; break;
case String::hash("NONE"): value = CompressionMode::e_none; break;
}
}
template<> void
StringStream<CompressionMode>::toString(const CompressionMode& value, StringAllocatingView& string)
{
switch (value) {
case CompressionMode::e_default: string.addAll("DEFAULT"); break;
case CompressionMode::e_best: string.addAll("BEST"); break;
case CompressionMode::e_none: string.addAll("NONE"); break;
default: lib_assert(false, "unknown value"); string.addAll(String(cast<uint01>(value))); break;
}
}
template<> void
StringStream<CompressionMode>::toDisplayString(const CompressionMode& value, TranslatedString& string)
{
switch (value) {
case CompressionMode::e_default_compression: string = _t("Default Compression"); break;
case CompressionMode::e_best_compression: string = _t("Best Compression"); break;
case CompressionMode::e_best_speed: string = _t("Best Speed"); break;
case CompressionMode::e_no_compression: string = _t("No Compression"); break;
case CompressionMode::e_string_compression: string = _t("String Compression"); break;
case CompressionMode::e_floating_point_compression: string = _t("Number Compression"); break;
default: lib_assert(false, "unknown value"); break;
}
}
constexpr uint08 hash() const
Creates a simple, quick hash of the object.
Definition String.h:524
@ e_none
No defined value type.
CompressionMode
Forward declaration of the Module struct for module metadata.
Definition Compressor.h:17
@ e_default_compression
Uses a sensible default compression strategy.
Definition Compressor.h:19
@ e_best_compression
Optimizes for smallest output at the cost of speed.
Definition Compressor.h:23
@ e_string_compression
Compression mode tailored for string data.
Definition Compressor.h:21
@ e_floating_point_compression
Generic floating-point compression.
Definition Compressor.h:22
@ e_no_compression
No compression is applied; data is stored raw.
Definition Compressor.h:18
@ e_best_speed
Optimizes for fastest compression at the cost of ratio.
Definition Compressor.h:20

Definition at line 253 of file StringStream.h.

Member Function Documentation

◆ fromString()

◆ getValidRegex()

template<class t_type>
const char * StringStream< t_type >::getValidRegex ( )
static

Optionally specified to allow the software to do a check on user or file input to ensure that fromString will return a valid result or to limit user live input.


Referenced by StringValidator::regex(), and QCustomLineEdit::setup().

◆ toDisplayString()

template<class t_type>
void StringStream< t_type >::toDisplayString ( const t_type & value,
TranslatedString & string )
static

Logic for converting an object to an NDEVR API translated, user facing string.


This allows the object to be shown in a unique way to a user. If not overwritten, will default to the value returned from toString

Referenced by String::DisplayString().

◆ toString()


The documentation for this class was generated from the following file: