Skip to content

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 ​

cpp
std::size_t size() const

Returns the number of positional fields

text ​

cpp
const std::string &text(std::size_t i) const

Parameters

ParameterDescription
i (in)positional index

Returns the raw (unescaped) positional field

cpp
const std::string &text(const std::string &key) const

Parameters

ParameterDescription
key (in)field key

Returns the raw (unescaped) value

cpp
std::string text(const std::string &key, const std::string &fallback) const

Parameters

ParameterDescription
key (in)field key
fallback (in)value for an absent or empty key

Returns the value

number ​

cpp
double number(std::size_t i) const

Parameters

ParameterDescription
i (in)positional index

Returns the field as a finite number

cpp
double number(const std::string &key) const

Parameters

ParameterDescription
key (in)field key

Returns the value as a finite number

cpp
double number(const std::string &key, double fallback) const

Parameters

ParameterDescription
key (in)field key
fallback (in)value for an absent or empty key

Returns the value

integer ​

cpp
int integer(std::size_t i) const

Parameters

ParameterDescription
i (in)positional index

Returns the field as an integral value in the int range

cpp
int integer(const std::string &key) const

Parameters

ParameterDescription
key (in)field key

Returns the value as an integral value in the int range

cpp
int integer(const std::string &key, int fallback) const

Parameters

ParameterDescription
key (in)field key
fallback (in)value for an absent or empty key

Returns the value

flag ​

cpp
bool flag(std::size_t i) const

Accepts "true", "1", "yes" and "on", or "false", "0", "no" and "off", as Engine 2 does.

Parameters

ParameterDescription
i (in)positional index

Returns the field as a flag

cpp
bool flag(const std::string &key) const

Parameters

ParameterDescription
key (in)field key

Returns the value as a flag (see flag(std::size_t))

cpp
bool flag(const std::string &key, bool fallback) const

Parameters

ParameterDescription
key (in)field key
fallback (in)value for an absent or empty key

Returns the value

vec3 ​

cpp
Vec3 vec3(std::size_t i) const

Parameters

ParameterDescription
i (in)index of the first of three positional fields

Returns fields i..i+2 as a vector

cpp
Vec3 vec3(const std::string &key) const

Parameters

ParameterDescription
key (in)field key

Returns the value, which must hold exactly three numbers

cpp
Vec3 vec3(const std::string &key, const Vec3 &fallback) const

Parameters

ParameterDescription
key (in)field key
fallback (in)value for an absent or empty key

Returns the value

quat ​

cpp
Quat quat(std::size_t i) const

Parameters

ParameterDescription
i (in)index of the first of four positional fields

Returns fields i..i+3 as (w, x, y, z)

has ​

cpp
bool has(const std::string &key) const

Parameters

ParameterDescription
key (in)field key

Returns true if the record has the key=value field

numbers ​

cpp
std::vector<double> numbers(const std::string &key) const

Comma- or semicolon-separated numbers.

Parameters

ParameterDescription
key (in)field key

Returns the parsed list; empty for an empty value

color ​

cpp
Color color(const std::string &key) const

Three or four components; alpha defaults to one.

Parameters

ParameterDescription
key (in)field key

Returns the color

cpp
Color color(const std::string &key, const Color &fallback) const

Parameters

ParameterDescription
key (in)field key
fallback (in)value for an absent or empty key

Returns the value

requireEmpty ​

cpp
void requireEmpty(const std::string &key) const

Fails unless the key holds an empty list (stored as "-").

Parameters

ParameterDescription
key (in)field key

vec2 ​

cpp
Vec2 vec2(const std::string &key, const Vec2 &fallback) const

Parameters

ParameterDescription
key (in)field key
fallback (in)value for an absent or empty key

Returns the value

optionalNumbers ​

cpp
std::vector<double> optionalNumbers(const std::string &key) const

Parameters

ParameterDescription
key (in)field key

Returns the list, or an empty list for an absent key

setText ​

cpp
void setText(std::size_t i, std::string value)

Replaces a positional field (see forEachFileReference()).

Parameters

ParameterDescription
i (in)positional index; throws if the record has no such field
value (in)new raw (unescaped) value

fail ​

cpp
void fail(const std::string &message) const

Throws std::runtime_error with the message, prefixed by the line number and tag.

Parameters

ParameterDescription
message (in)error description

Static member functions ​

parse static ​

cpp
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

ParameterDescription
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 ​

cpp
std::string tag

The record tag (first token of the line). Empty for a blank line.

line ​

cpp
std::size_t line

Line number in the file (1-based when read by load()).

RaiSim — physics for robotics and AI.