Smart way of solving marshalling datatypes from library to C++ primatives -


i'm using library (don't have access sources) has it's own data types, e.g. library::object::library_string, library::object::library_number. there enum stored alongside type tells type (i.e. library::object::type)

the library provides methods on library::object isstring(), isnumber() query type. library provides getstring(), getnumber() throw exception if called on wrong type.

i'm using library application , want populate c++ primitives little tedious code possible. 1 issue because library::object null or unexpected type, should check type using isxxxx() use getxxxx() populated c++ model.

to prevent lots of code mymodel.myprimativevariable = isxxxx() ? getxxxx() : null_condition_type_for_this_type "" or 0

what's best achieve this? it's shame library didn't provide trygetvalue() method.

i write bunch of functions each type (different signatures) can do:

mymodel->myint = getintvalue(objectinstance) mymodel->mystring = getstringvalue(objectinstance)

where objectinstance library::object instance

or use templates , have 1 function tries cast type template type.

i've encountered 'problem' before , opt write wrappers, feels naive. feel must 'solved' problem. think there better ways?

thanks


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo