1#include "component_format.h"
3#include <cgv/utils/tokenizer.h>
5#include <cgv/type/info/type_name.h>
6#include <cgv/type/info/type_id.h>
14static const char* component_formats[] = {
67 unsigned align,
unsigned d0,
unsigned d1,
unsigned d2,
unsigned d3)
68 :
packing_info(align, d0,d1,d2,d3), component_type(_type_id), component_string(_components)
76 unsigned align,
unsigned d0,
unsigned d1,
unsigned d2,
unsigned d3)
77 :
packing_info(align, d0,d1,d2,d3), component_type(_type_id),
78 component_string(component_formats[cf])
98 else if (tok[0] ==
's')
102 if (tok.size() == 1) {
103 component_type = TI_UNDEF;
110 bool is_signed =
true;
111 if (ci == CII_INTEGER && tok[1] ==
'u') {
115 if (tok[offset] !=
'i')
117 if (tok[offset + 1] !=
'n')
119 if (tok[offset + 2] !=
't')
122 if (!((tok.size() == offset + 4) && (tok[offset + 3] ==
'8'))) {
123 if (tok.size() != offset + 5)
125 switch (tok[offset + 3]) {
128 if (tok[offset + 4] !=
'6')
133 if (tok[offset + 4] !=
'2')
138 if (tok[offset + 4] !=
'4')
168 if (description.empty()) {
172 std::vector<token> toks;
174 if (toks.size() == 0) {
175 last_error =
"no tokens found that would define a component format";
197 if (toks.size() == i) {
198 last_error =
"description incomplete after <type_name>";
201 if (toks[i] ==
":") {
202 if (toks.size() == ++i) {
203 last_error =
"description incomplete after <type_name:>";
208 for (
int ci=0; ci<4; ++ci)
214 last_error =
"expected integer token after <type_name:>";
218 if (toks[i] ==
"|") {
219 if (toks.size() == ++i) {
220 last_error =
"description incomplete after <type_name|>";
229 last_error =
"expected integer token after <type_name|>";
233 if (toks.size() == i) {
234 last_error =
"description incomplete after <type_name>";
238 if (toks[i] !=
"[") {
242 if (toks.size() == ++i) {
243 last_error =
"description incomplete after <[>";
247 while (toks[i] !=
"]") {
251 if (toks.size() == ++i) {
252 last_error =
"description incomplete after <[ or ,>";
255 if (toks[i] ==
":") {
256 if (toks.size() == ++i) {
257 last_error =
"description incomplete after <component_name:>";
265 if (toks.size() == ++i) {
266 last_error =
"description incomplete after <component_name:bit_depth>";
271 last_error =
"expected integer token after <component_name:>";
275 if (toks[i] ==
",") {
276 if (toks.size() == ++i) {
277 last_error =
"description incomplete after <,>";
353 std::string component_name_list;
355 if (!component_name_list.empty())
356 component_name_list +=
',';
360 if (component_name_list == component_formats[cf])
394 unsigned nr_bits = 0;
397 return unsigned(
align(nr_bits, 8)/8);
425 return !(*
this == cf);
430 case CII_SNORM: os <<
's';
break;
431 case CII_INTEGER: os <<
'_';
break;
436 bool individual_bit_depth =
false;
443 individual_bit_depth =
true;
452 if (individual_bit_depth)
464 if (cf != CF_UNDEF) {
467 if ((cf1 == cf) != (cf2 == cf))
474 if ((nc1 == nc) != (nc2 == nc))
476 if ((nc1 >= nc) != (nc2 >= nc))
483 if ((ti1 == ti) != (ti2 == ti))
490 if ((cii1 == cii) != (cii2 == cii))
497 if ((ip1 == ip) != (ip2 == ip))
501 unsigned int diff1 = 0;
502 unsigned int diff2 = 0;
503 for (
unsigned int i=0; i<nc; ++i) {
531 return diff1 < diff2;
538 const char** format_descriptions,
540 bool (*fmt1_better_match)(
546 unsigned int best_i = -1;
553 ++format_descriptions;
556 while (*format_descriptions) {
558 if (!fmt1_better_match(fmt, best_match, fmt1)) {
562 ++format_descriptions;
the packing_info class stores information about packed integers structures.
static size_t align(size_t v, unsigned a)
return the next integer larger or equal to v which is dividable by a
bool is_packing() const
return whether packing is enabled
void set_bit_depth(unsigned ci, unsigned depth)
set the bit depth of the ci-th component
unsigned get_bit_depth(unsigned ci) const
return the bit depth of the ci-th component
unsigned int get_component_alignment() const
return the component alignment in bits in the packed case and in bytes in the unpacked case
void set_packing(bool enable=true)
set the packing flag
void set_component_alignment(unsigned a)
set the component alignment in bits in the packed case and in bytes in the unpacked case
void clear()
clear packing info information
the tokenizer allows to split text into tokens in a convenient way.
tokenizer & set_sep(const std::string &sep, bool merge)
set the list of separators and specify whether succeeding separators are merged into single tokens
ComponentFormat
define standard formats, which should be used to avoid wrong assignment of component names
@ CF_LAST
texture coordinats format with components ts, tt, tr and tq
std::ostream & operator<<(std::ostream &os, const component_format &cf)
stream out operator writes the component format in the syntax of description strings as defined in th...
unsigned find_best_match(const component_format &fmt, const char **format_descriptions, const component_format *fmt0, bool(*fmt1_better_match)(const component_format &fmt, const component_format &fmt1, const component_format &fmt2))
find the best matching format in a list of formats described by strings and return index of best matc...
ComponentIntegerInterpretation
define different interpretations of integer components
bool fmt1_compares_better(const component_format &fmt, const component_format &fmt1, const component_format &fmt2)
default function to check whether fmt1 is a better match to fmt than fmt2
namespace for templates that provide type information
TypeId get_type_id(const std::string &_type_name)
function that returns the type id of a type name
unsigned int get_type_size(TypeId tid)
function that returns the size of a type specified through TypeId
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
TypeId
ids for the different types and type constructs
@ TI_INT16
signed integer stored in 8 bits
@ TI_INT32
signed integer stored in 16 bits
@ TI_UINT32
unsigned integer stored in 16 bits
@ TI_UINT8
signed integer stored in 64 bits
@ TI_INT64
signed integer stored in 32 bits
@ TI_UINT16
unsigned integer stored in 8 bits
@ TI_UINT64
unsigned integer stored in 32 bits
namespace that holds tools that dont fit any other namespace
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
bool is_integer(const char *begin, const char *end, int &value)
check if the text range (begin,end( defines an integer value. If yes, store the value in the passed r...
Helper functions to process strings.