API Documentation
Loading...
Searching...
No Matches
StringStream< t_type > Class Template Reference

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

#include <StringStream.h>

Static Public Member Functions

static void fromString (const String &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. 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.
 
static void toString (const t_type &value, String &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 NDEVR::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, String& string)
{
string.addAll(value.toUtf8().constData());
}
//No need to override toDisplayString as no custom way to show this data to the user
The core String class for the NDEVR API.
Definition String.h:69
static void toString(const t_type &value, String &string)
Logic for converting an object to an NDEVR API String allowing it to be used automatically with the S...
static void fromString(const String &string, t_type &value)
Logic for converting an object from an NDEVR API String allowing it to be used automatically with get...

Example Code For automatic conversion from a non-trivial structure

template<> void StringStream<KeyEvent>::fromString(const String& 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, String& 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::SHIFT && value.key_type != KeyEvent::LIB_VK_SHIFT)
string += _t("SHIFT").translation()+"+";
if (value.key_modifier & KeyEvent::CTRL && value.key_type != KeyEvent::LIB_VK_RCONTROL && value.key_type != KeyEvent::LIB_VK_LCONTROL)
string += _t("CTRL").translation() + "+";
if (value.key_modifier & KeyEvent::FUNCTION)
string += _t("FUNCTION").translation() + "+";
if (value.key_modifier & KeyEvent::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);
}
#define _t(english_string)
Definition Translator.h:90
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
constexpr t_index_type size() const
Definition Buffer.hpp:823
Buffer< t_other_type, t_other_index_type, t_other_memory_allocator, 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:172
A class which describes a user key press.
Definition Event.h:49
KeyEentType event_type
Definition Event.h:284
@ LIB_VK_BUTTON_R1
Definition Event.h:218
@ VK_KEY_F14
Definition Event.h:154
@ LIB_VK_DELETE
Definition Event.h:75
@ LIB_VK_BUTTON_A
Definition Event.h:213
@ VK_KEY_F15
Definition Event.h:155
@ LIB_VK_META
Definition Event.h:79
@ VK_KEY_F1
Definition Event.h:141
@ VK_KEY_F5
Definition Event.h:145
@ VK_KEY_F24
Definition Event.h:164
@ LIB_VK_VOLUME_DOWN
Definition Event.h:226
@ LIB_VK_BUTTON_L1
Definition Event.h:217
@ VK_KEY_F13
Definition Event.h:153
@ LIB_VK_BUTTON_MODE
Definition Event.h:221
@ LIB_VK_ESCAPE
Definition Event.h:82
@ LIB_VK_MENU
Definition Event.h:80
@ LIB_VK_LCONTROL
Definition Event.h:77
@ VK_KEY_F21
Definition Event.h:161
@ VK_KEY_F10
Definition Event.h:150
@ VK_KEY_F12
Definition Event.h:152
@ LIB_VK_BUTTON_THUMBR
Definition Event.h:223
@ VK_KEY_F18
Definition Event.h:158
@ LIB_VK_RCONTROL
Definition Event.h:78
@ VK_KEY_F4
Definition Event.h:144
@ VK_KEY_F6
Definition Event.h:146
@ LIB_VK_SPACE
Definition Event.h:206
@ VK_KEY_F23
Definition Event.h:163
@ VK_KEY_F16
Definition Event.h:156
@ LIB_VK_BUTTON_SELECT
Definition Event.h:219
@ LIB_VK_VOLUME_UP
Definition Event.h:225
@ VK_KEY_F20
Definition Event.h:160
@ LIB_VK_RETURN
Definition Event.h:203
@ VK_KEY_F2
Definition Event.h:142
@ VK_KEY_F17
Definition Event.h:157
@ VK_KEY_F22
Definition Event.h:162
@ LIB_VK_BUTTON_Y
Definition Event.h:216
@ LIB_VK_BUTTON_X
Definition Event.h:215
@ LIB_VK_BUTTON_B
Definition Event.h:214
@ LIB_VK_SHIFT
Definition Event.h:69
@ VK_KEY_F8
Definition Event.h:148
@ LIB_VK_BUTTON_THUMBL
Definition Event.h:222
@ VK_KEY_F7
Definition Event.h:147
@ VK_KEY_F9
Definition Event.h:149
@ LIB_VK_BUTTON_START
Definition Event.h:220
@ LIB_VK_EXECUTE
Definition Event.h:83
@ VK_KEY_F11
Definition Event.h:151
@ VK_KEY_F3
Definition Event.h:143
@ VK_KEY_F19
Definition Event.h:159
@ SHIFT
Definition Event.h:265
@ CTRL
Definition Event.h:266
@ FUNCTION
Definition Event.h:267
@ ALT
Definition Event.h:268
uint01 key_modifier
Definition Event.h:283
KEY key_type
Definition Event.h:282
static void toDisplayString(const t_type &value, TranslatedString &string)
Logic for converting an object to an NDEVR API translated, user facing string. This allows the object...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375

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
{
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;
}
}
#define lib_assert(expression, message)
Definition LibAssert.h:61
uint08 hash() const
Creates a simple, quick hash of the object. See hash(const char* value) for details of the implementa...
CompressionMode
Logical information about the type of compression implemented or requested.
Definition Compressor.h:16
@ e_best_compression
Definition Compressor.h:22
@ e_default_compression
Definition Compressor.h:18
@ e_no_compression
Definition Compressor.h:17
@ e_string_compression
Definition Compressor.h:20
@ e_best_speed
Definition Compressor.h:19
@ e_floating_point_compression
Definition Compressor.h:21
@ e_best
Definition RibbonLayoutMode.hpp:40

Member Function Documentation

◆ fromString()

template<class t_type >
static void fromString ( const String & string,
t_type & value )
static

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.


◆ getValidRegex()

template<class t_type >
static const char * 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.


◆ toDisplayString()

template<class t_type >
static void 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.


◆ toString()

template<class t_type >
static void toString ( const t_type & value,
String & string )
static

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.



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