FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
variant.cpp
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Dec 30, 2011
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2010 Richard Bateman, Firebreath development team
13 \**********************************************************/
14 
15 #include "variant.h"
16 #include "precompiled_headers.h" // On windows, everything above this line in PCH
17 
18 using FB::variant;
19 
20 variant FB::variant_detail::conversion::make_variant(const char* x) {
21  return variant(std::string(x), true);
22 }
23 variant FB::variant_detail::conversion::make_variant(const wchar_t* x) {
24  return variant(std::wstring(x), true);
25 }
27 // variant convert_cast helpers
28 //
29 // These functions are called to process any
30 // values assigned to the variant. For example,
31 // all const char* parameters are converted to
32 // std::string
34 
35 const void FB::variant_detail::conversion::convert_variant(const FB::variant&, const FB::variant_detail::conversion::type_spec<void>) {
36  return;
37 }
38 
39 const FB::variant& FB::variant_detail::conversion::convert_variant(const FB::variant& var, const FB::variant_detail::conversion::type_spec<FB::variant>) {
40  return var;
41 }
42 
43 const FB::FBNull FB::variant_detail::conversion::convert_variant( const FB::variant&, const type_spec<FB::FBNull> )
44 {
45  return FB::FBNull();
46 }
47 
48 const FB::FBVoid FB::variant_detail::conversion::convert_variant( const FB::variant&, const type_spec<FB::FBVoid> )
49 {
50  return FB::FBVoid();
51 }
52 
53 FB::variant FB::variant_detail::conversion::make_variant(const boost::tribool& val) {
54  if (boost::indeterminate(val))
55  return FB::variant();
56  else
57  return (bool)val;
58 }
59 boost::tribool FB::variant_detail::conversion::convert_variant( const FB::variant& var, const type_spec<boost::tribool>& )
60 {
61  if (var.is_null() || var.empty())
62  return boost::indeterminate;
63  else
64  return var.convert_cast<bool>();
65 }
66 
const T convert_cast() const
Converts the stored value to the requested type if possible and returns the resulting value...
Definition: variant.h:667
Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out t...
Definition: variant.h:198
bool empty() const
Returns true if the variant is empty (has not been assigned a value or has been reset) ...
Definition: variant.h:403