File: parsehi.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (61 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "parsehi.h"
#include "globalincs/vmallocator.h"
#include "parselo.h"
#include "graphics/color.h"

/**
 * @brief Parses an optional table value into a field if the name is found
 *
 * @param field_name The name of the table field
 * @param value_target Pointer to the variable to assign any parsed value to
 *
 * @return True if a value was parsed, false if not
 */
bool parse_optional_float_into(const SCP_string& field_name, float* value_target)
{
	if (optional_string(field_name.c_str())) {
		stuff_float(value_target);
		return true;
	}
	return false;
}

/**
 * @brief Parses an optional table value into a field if the name is found
 *
 * @param field_name The name of the table field
 * @param value_target Pointer to the variable to assign any parsed value to
 *
 * @return True if a value was parsed, false if not
 */
bool parse_optional_bool_into(const SCP_string& field_name, bool* value_target)
{
	if (optional_string(field_name.c_str())) {
		stuff_boolean(value_target);
		return true;
	}
	return false;
}

/**
 * @brief Parses an optional table color into an object if the color is found
 *
 * @param field_name The name of the table field
 * @param value_target Pointer to the variable to assign any parsed value to
 *
 * @return True if a value was parsed, false if not
 */
bool parse_optional_color3i_into(const SCP_string& field_name, hdr_color* out_color)
{
	if (optional_string(field_name.c_str())) {
		int components[3] = {255, 255, 255};
		stuff_int_list(components, 3, RAW_INTEGER_TYPE);
		if (out_color == nullptr) {
			Assertion(out_color,"out_color pointer is null for field %s",field_name.c_str());
			return false;
		}
		out_color->set_rgb(components);
		return true;
	}
	return false;
}