raisim::rscene::Record
class · #include <raisim/Rscene.hpp>
One line of the file. Positional fields keep their order; keys are unique. The required accessors throw std::runtime_error, naming the line, when a value is missing or malformed. The accessors that take a fallback return it when the key is absent or its value is empty ("-"), as Engine 2 does, and throw only for a malformed value.
Public member functions
size
std::size_t size() constReturns the number of positional fields
text
const std::string &text(std::size_t i) constParameters
| Parameter | Description |
|---|---|
i (in) | positional index |
Returns the raw (unescaped) positional field
const std::string &text(const std::string &key) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the raw (unescaped) value
std::string text(const std::string &key, const std::string &fallback) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
fallback (in) | value for an absent or empty key |
Returns the value
number
double number(std::size_t i) constParameters
| Parameter | Description |
|---|---|
i (in) | positional index |
Returns the field as a finite number
double number(const std::string &key) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the value as a finite number
double number(const std::string &key, double fallback) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
fallback (in) | value for an absent or empty key |
Returns the value
integer
int integer(std::size_t i) constParameters
| Parameter | Description |
|---|---|
i (in) | positional index |
Returns the field as an integral value in the int range
int integer(const std::string &key) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the value as an integral value in the int range
int integer(const std::string &key, int fallback) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
fallback (in) | value for an absent or empty key |
Returns the value
flag
bool flag(std::size_t i) constAccepts "true", "1", "yes" and "on", or "false", "0", "no" and "off", as Engine 2 does.
Parameters
| Parameter | Description |
|---|---|
i (in) | positional index |
Returns the field as a flag
bool flag(const std::string &key) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the value as a flag (see flag(std::size_t))
bool flag(const std::string &key, bool fallback) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
fallback (in) | value for an absent or empty key |
Returns the value
vec3
Vec3 vec3(std::size_t i) constParameters
| Parameter | Description |
|---|---|
i (in) | index of the first of three positional fields |
Returns fields i..i+2 as a vector
Vec3 vec3(const std::string &key) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the value, which must hold exactly three numbers
Vec3 vec3(const std::string &key, const Vec3 &fallback) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
fallback (in) | value for an absent or empty key |
Returns the value
quat
Quat quat(std::size_t i) constParameters
| Parameter | Description |
|---|---|
i (in) | index of the first of four positional fields |
Returns fields i..i+3 as (w, x, y, z)
has
bool has(const std::string &key) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns true if the record has the key=value field
numbers
std::vector<double> numbers(const std::string &key) constComma- or semicolon-separated numbers.
Parameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the parsed list; empty for an empty value
color
Color color(const std::string &key) constThree or four components; alpha defaults to one.
Parameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the color
Color color(const std::string &key, const Color &fallback) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
fallback (in) | value for an absent or empty key |
Returns the value
requireEmpty
void requireEmpty(const std::string &key) constFails unless the key holds an empty list (stored as "-").
Parameters
| Parameter | Description |
|---|---|
key (in) | field key |
vec2
Vec2 vec2(const std::string &key, const Vec2 &fallback) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
fallback (in) | value for an absent or empty key |
Returns the value
optionalNumbers
std::vector<double> optionalNumbers(const std::string &key) constParameters
| Parameter | Description |
|---|---|
key (in) | field key |
Returns the list, or an empty list for an absent key
setText
void setText(std::size_t i, std::string value)Replaces a positional field (see forEachFileReference()).
Parameters
| Parameter | Description |
|---|---|
i (in) | positional index; throws if the record has no such field |
value (in) | new raw (unescaped) value |
fail
void fail(const std::string &message) constThrows std::runtime_error with the message, prefixed by the line number and tag.
Parameters
| Parameter | Description |
|---|---|
message (in) | error description |
Static member functions
parse static
static Record parse(std::string_view text, std::size_t line)Tokenizes one line on spaces, tabs and carriage returns. The first token is the tag, tokens without '=' are positional fields and must precede all key=value fields. Values are unescaped: "%XX" is a hex-encoded byte and a lone "-" is an empty value. A line whose first character (after white space) is '#' is a comment: the record has the tag "#" and no fields.
Parameters
| Parameter | Description |
|---|---|
text (in) | the line |
line (in) | line number used in error messages |
Returns the parsed record. Throws on a duplicate key or a positional field after a key
Public attributes
tag
std::string tagThe record tag (first token of the line). Empty for a blank line.
line
std::size_t lineLine number in the file (1-based when read by load()).