OpenDDS  Snapshot(2023/01/24-11:31)
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
OpenDDS::DCPS::Value Struct Reference

#include <FilterEvaluator.h>

Collaboration diagram for OpenDDS::DCPS::Value:
Collaboration graph
[legend]

Public Types

enum  Type {
  VAL_BOOL, VAL_INT, VAL_UINT, VAL_I64,
  VAL_UI64, VAL_FLOAT, VAL_LNGDUB, VAL_LARGEST_NUMERIC = VAL_LNGDUB,
  VAL_CHAR, VAL_STRING
}
 

Public Member Functions

 Value (bool b, bool conversion_preferred=false)
 
 Value (int i, bool conversion_preferred=false)
 
 Value (unsigned int u, bool conversion_preferred=false)
 
 Value (ACE_INT64 l, bool conversion_preferred=false)
 
 Value (ACE_UINT64 m, bool conversion_preferred=false)
 
 Value (char c, bool conversion_preferred=false)
 
 Value (double f, bool conversion_preferred=false)
 
 Value (ACE_CDR::LongDouble ld, bool conversion_preferred=false)
 
 Value (const char *s, bool conversion_preferred=false)
 
 Value (const std::string &s, bool conversion_preferred=false)
 
 Value (const TAO::String_Manager &s, bool conversion_preferred=false)
 
 Value (const TAO::WString_Manager &s, bool conversion_preferred=false)
 
 ~Value ()
 
 Value (const Value &v)
 
Valueoperator= (const Value &v)
 
void swap (Value &other)
 
bool operator== (const Value &v) const
 
bool operator< (const Value &v) const
 
bool like (const Value &v) const
 
Value operator% (const Value &v) const
 
bool convert (Type t)
 
template<typename T >
T & get ()
 
template<typename T >
const T & get () const
 
template<>
bool & get ()
 
template<>
int & get ()
 
template<>
unsigned int & get ()
 
template<>
ACE_INT64get ()
 
template<>
ACE_UINT64get ()
 
template<>
char & get ()
 
template<>
double & get ()
 
template<>
ACE_CDR::LongDoubleget ()
 
template<>
const char *& get ()
 
template<>
const bool & get () const
 
template<>
const int & get () const
 
template<>
const unsigned int & get () const
 
template<>
const ACE_INT64get () const
 
template<>
const ACE_UINT64get () const
 
template<>
const char & get () const
 
template<>
const double & get () const
 
template<>
const ACE_CDR::LongDoubleget () const
 
template<>
const char *const & get () const
 

Static Public Member Functions

static void conversion (Value &lhs, Value &rhs)
 

Public Attributes

Type type_
 
union {
   bool   b_
 
   int   i_
 
   unsigned int   u_
 
   ACE_INT64   l_
 
   ACE_UINT64   m_
 
   char   c_
 
   double   f_
 
   ACE_CDR::LongDouble   ld_
 
   const char *   s_
 
}; 
 
bool conversion_preferred_
 

Detailed Description

Definition at line 37 of file FilterEvaluator.h.

Member Enumeration Documentation

◆ Type

enum OpenDDS::DCPS::Value::Type

Constructor & Destructor Documentation

◆ Value() [1/13]

OpenDDS::DCPS::Value::Value ( bool  b,
bool  conversion_preferred = false 
)

Definition at line 569 of file FilterEvaluator.cpp.

Referenced by Value().

◆ Value() [2/13]

OpenDDS::DCPS::Value::Value ( int  i,
bool  conversion_preferred = false 
)

◆ Value() [3/13]

OpenDDS::DCPS::Value::Value ( unsigned int  u,
bool  conversion_preferred = false 
)

Definition at line 577 of file FilterEvaluator.cpp.

◆ Value() [4/13]

OpenDDS::DCPS::Value::Value ( ACE_INT64  l,
bool  conversion_preferred = false 
)

Definition at line 581 of file FilterEvaluator.cpp.

◆ Value() [5/13]

OpenDDS::DCPS::Value::Value ( ACE_UINT64  m,
bool  conversion_preferred = false 
)

Definition at line 585 of file FilterEvaluator.cpp.

◆ Value() [6/13]

OpenDDS::DCPS::Value::Value ( char  c,
bool  conversion_preferred = false 
)

◆ Value() [7/13]

OpenDDS::DCPS::Value::Value ( double  f,
bool  conversion_preferred = false 
)

◆ Value() [8/13]

OpenDDS::DCPS::Value::Value ( ACE_CDR::LongDouble  ld,
bool  conversion_preferred = false 
)

◆ Value() [9/13]

OpenDDS::DCPS::Value::Value ( const char *  s,
bool  conversion_preferred = false 
)

Definition at line 609 of file FilterEvaluator.cpp.

References strdup().

611  , conversion_preferred_(conversion_preferred)
612 {}
char * strdup(const char *s)

◆ Value() [10/13]

OpenDDS::DCPS::Value::Value ( const std::string &  s,
bool  conversion_preferred = false 
)

Definition at line 614 of file FilterEvaluator.cpp.

References conversion_preferred_, s_, strdup(), ACE_OS::strdup(), type_, VAL_STRING, and Value().

615  : type_(VAL_STRING), s_(ACE_OS::strdup(s.c_str()))
616  , conversion_preferred_(conversion_preferred)
617 {}
char * strdup(const char *s)

◆ Value() [11/13]

OpenDDS::DCPS::Value::Value ( const TAO::String_Manager s,
bool  conversion_preferred = false 
)

Definition at line 626 of file FilterEvaluator.cpp.

References strdup().

627  : type_(VAL_STRING), s_(ACE_OS::strdup(s.in()))
628  , conversion_preferred_(conversion_preferred)
629 {}
char * strdup(const char *s)

◆ Value() [12/13]

OpenDDS::DCPS::Value::Value ( const TAO::WString_Manager s,
bool  conversion_preferred = false 
)

Definition at line 631 of file FilterEvaluator.cpp.

References strdup().

632  : type_(VAL_STRING)
633 #ifdef DDS_HAS_WCHAR
634  , s_(ACE_OS::strdup(ACE_Wide_To_Ascii(s.in()).char_rep()))
635 #else
636  , s_(0)
637 #endif
638  , conversion_preferred_(conversion_preferred)
639 {
640 #ifndef DDS_HAS_WCHAR
641  ACE_UNUSED_ARG(s);
642 #endif
643 }
char * strdup(const char *s)

◆ ~Value()

OpenDDS::DCPS::Value::~Value ( )

◆ Value() [13/13]

OpenDDS::DCPS::Value::Value ( const Value v)

Definition at line 722 of file FilterEvaluator.cpp.

723  : type_(v.type_), conversion_preferred_(v.conversion_preferred_)
724 {
725  Assign visitor(*this);
726  visit(visitor, v);
727 }

Member Function Documentation

◆ conversion()

void OpenDDS::DCPS::Value::conversion ( Value lhs,
Value rhs 
)
static

Definition at line 949 of file FilterEvaluator.cpp.

References conversion_preferred_, convert(), type_, VAL_CHAR, VAL_LARGEST_NUMERIC, and VAL_STRING.

Referenced by operator%(), operator<(), and operator==().

950 {
951  if (lhs.type_ == rhs.type_) {
952  return;
953  }
954  bool ok = false;
955  Value& smaller = (lhs.type_ < rhs.type_) ? lhs : rhs;
956  Value& larger = (lhs.type_ < rhs.type_) ? rhs : lhs;
957  if (smaller.conversion_preferred_) {
958  ok = smaller.convert(larger.type_);
959  } else if (larger.conversion_preferred_) {
960  ok = larger.convert(smaller.type_);
961  } else if (smaller.type_ == VAL_CHAR && larger.type_ == VAL_STRING) {
962  ok = smaller.convert(VAL_STRING);
963  } else if (larger.type_ <= VAL_LARGEST_NUMERIC) {
964  ok = smaller.convert(larger.type_);
965  } else if (larger.type_ == VAL_STRING) {
966  if (larger.convert(smaller.type_)) {
967  ok = true;
968  } else {
969  ok = smaller.convert(VAL_STRING);
970  }
971  }
972  if (!ok) {
973  throw std::runtime_error("Types don't match and aren't convertible.");
974  }
975 }
any Value

◆ convert()

bool OpenDDS::DCPS::Value::convert ( Type  t)

Definition at line 917 of file FilterEvaluator.cpp.

References conversion_preferred_, OPENDDS_STRING, s_, ACE_OS::strdup(), swap(), type_, and VAL_STRING.

Referenced by conversion().

918 {
919  OPENDDS_STRING asString;
920  if (type_ == VAL_STRING) {
921  asString = s_;
922  } else {
923  std::ostringstream oss;
924  StreamInsert visitor(oss);
925  visit(visitor, *this);
926  asString = oss.str();
927  }
928 
929  Value newval = 0;
930  newval.type_ = t;
931  newval.conversion_preferred_ = false;
932  if (t == VAL_STRING) {
933  newval.s_ = ACE_OS::strdup(asString.c_str());
934  swap(newval);
935  return true;
936  } else {
937  std::istringstream iss(asString);
938  StreamExtract visitor(iss);
939  visit(visitor, newval);
940  if (iss.eof() && !iss.bad()) {
941  swap(newval);
942  return true;
943  }
944  return false;
945  }
946 }
void swap(Value &other)
char * strdup(const char *s)
#define OPENDDS_STRING
any Value

◆ get() [1/20]

template<typename T >
T& OpenDDS::DCPS::Value::get ( )

◆ get() [2/20]

template<typename T >
const T& OpenDDS::DCPS::Value::get ( ) const

◆ get() [3/20]

template<>
bool& OpenDDS::DCPS::Value::get ( void  )

Definition at line 645 of file FilterEvaluator.cpp.

References b_.

645 { return b_; }

◆ get() [4/20]

template<>
int& OpenDDS::DCPS::Value::get ( void  )

Definition at line 646 of file FilterEvaluator.cpp.

References i_.

646 { return i_; }

◆ get() [5/20]

template<>
unsigned int& OpenDDS::DCPS::Value::get ( void  )

Definition at line 647 of file FilterEvaluator.cpp.

References u_.

647 { return u_; }

◆ get() [6/20]

template<>
ACE_INT64& OpenDDS::DCPS::Value::get ( void  )

Definition at line 648 of file FilterEvaluator.cpp.

References l_.

648 { return l_; }

◆ get() [7/20]

template<>
ACE_UINT64& OpenDDS::DCPS::Value::get ( void  )

Definition at line 649 of file FilterEvaluator.cpp.

References m_.

649 { return m_; }

◆ get() [8/20]

template<>
char& OpenDDS::DCPS::Value::get ( void  )

Definition at line 650 of file FilterEvaluator.cpp.

References c_.

650 { return c_; }

◆ get() [9/20]

template<>
double& OpenDDS::DCPS::Value::get ( void  )

Definition at line 651 of file FilterEvaluator.cpp.

References f_.

651 { return f_; }

◆ get() [10/20]

template<>
ACE_CDR::LongDouble& OpenDDS::DCPS::Value::get ( void  )

Definition at line 652 of file FilterEvaluator.cpp.

References ld_.

652 { return ld_; }
ACE_CDR::LongDouble ld_

◆ get() [11/20]

template<>
const char*& OpenDDS::DCPS::Value::get ( void  )

Definition at line 653 of file FilterEvaluator.cpp.

References s_.

653 { return s_; }

◆ get() [12/20]

template<>
const bool& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 655 of file FilterEvaluator.cpp.

References b_.

655 { return b_; }

◆ get() [13/20]

template<>
const int& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 656 of file FilterEvaluator.cpp.

References i_.

656 { return i_; }

◆ get() [14/20]

template<>
const unsigned int& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 657 of file FilterEvaluator.cpp.

References u_.

657 { return u_; }

◆ get() [15/20]

template<>
const ACE_INT64& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 658 of file FilterEvaluator.cpp.

References l_.

658 { return l_; }

◆ get() [16/20]

template<>
const ACE_UINT64& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 659 of file FilterEvaluator.cpp.

References m_.

659 { return m_; }

◆ get() [17/20]

template<>
const char& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 660 of file FilterEvaluator.cpp.

References c_.

660 { return c_; }

◆ get() [18/20]

template<>
const double& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 661 of file FilterEvaluator.cpp.

References f_.

661 { return f_; }

◆ get() [19/20]

template<>
const ACE_CDR::LongDouble& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 662 of file FilterEvaluator.cpp.

References ld_.

662 { return ld_; }
ACE_CDR::LongDouble ld_

◆ get() [20/20]

template<>
const char* const& OpenDDS::DCPS::Value::get ( void  ) const

Definition at line 663 of file FilterEvaluator.cpp.

References s_.

663 { return s_; }

◆ like()

bool OpenDDS::DCPS::Value::like ( const Value v) const

Definition at line 859 of file FilterEvaluator.cpp.

References OPENDDS_STRING, os_, s_, type_, VAL_STRING, and ACE::wild_match().

860 {
861  if (type_ != VAL_STRING || v.type_ != VAL_STRING) {
862  throw std::runtime_error("'like' operator called on non-string arguments.");
863  }
864  OPENDDS_STRING pattern(v.s_);
865  // escape ? or * in the pattern string so they are not wildcards
866  for (size_t i = pattern.find_first_of("?*"); i < pattern.length();
867  i = pattern.find_first_of("?*", i + 1)) {
868  pattern.insert(i++, 1, '\\');
869  }
870  // translate _ and % wildcards into those used by ACE::wild_match() (?, *)
871  for (size_t i = pattern.find_first_of("_%"); i < pattern.length();
872  i = pattern.find_first_of("_%", i + 1)) {
873  pattern[i] = (pattern[i] == '_') ? '?' : '*';
874  }
875  return ACE::wild_match(s_, pattern.c_str(), true, true);
876 }
#define OPENDDS_STRING
bool wild_match(const char *s, const char *pattern, bool case_sensitive=true, bool character_classes=false)

◆ operator%()

Value OpenDDS::DCPS::Value::operator% ( const Value v) const

Definition at line 849 of file FilterEvaluator.cpp.

References conversion().

850 {
851  Value lhs = *this;
852  Value rhs = v;
853  conversion(lhs, rhs);
854  Modulus visitor(lhs);
855  return visit(visitor, rhs);
856 }
static void conversion(Value &lhs, Value &rhs)
any Value

◆ operator<()

bool OpenDDS::DCPS::Value::operator< ( const Value v) const

Definition at line 839 of file FilterEvaluator.cpp.

References conversion().

840 {
841  Value lhs = *this;
842  Value rhs = v;
843  conversion(lhs, rhs);
844  Less visitor(lhs);
845  return visit(visitor, rhs);
846 }
static void conversion(Value &lhs, Value &rhs)
any Value

◆ operator=()

Value & OpenDDS::DCPS::Value::operator= ( const Value v)

Definition at line 730 of file FilterEvaluator.cpp.

References swap().

731 {
732  Value cpy(v);
733  swap(cpy);
734  return *this;
735 }
void swap(Value &other)
any Value

◆ operator==()

bool OpenDDS::DCPS::Value::operator== ( const Value v) const

Definition at line 829 of file FilterEvaluator.cpp.

References conversion().

830 {
831  Value lhs = *this;
832  Value rhs = v;
833  conversion(lhs, rhs);
834  Equals visitor(lhs);
835  return visit(visitor, rhs);
836 }
static void conversion(Value &lhs, Value &rhs)
any Value

◆ swap()

void OpenDDS::DCPS::Value::swap ( Value other)

Definition at line 738 of file FilterEvaluator.cpp.

References conversion_preferred_, ACE_OS::free(), lhs_, s_, OpenDDS::DCPS::swap(), type_, and VAL_STRING.

Referenced by convert(), and operator=().

739 {
740  Value t(v);
741 
742  if (v.type_ == VAL_STRING) {
743  ACE_OS::free((void*)v.s_);
744  }
745 
746  Assign visitor1(v, true);
747  visit(visitor1, *this);
748  if (type_ == VAL_STRING) {
749  s_ = 0;
750  }
751 
752  Assign visitor2(*this, true);
753  visit(visitor2, t);
754  if (t.type_ == VAL_STRING) {
755  t.s_ = 0;
756  }
757 
758  std::swap(conversion_preferred_, v.conversion_preferred_);
759  std::swap(type_, v.type_);
760 }
void free(void *)
void swap(RawDataSample &lhs, RawDataSample &rhs)
any Value

Member Data Documentation

◆ @2

union { ... }

◆ b_

bool OpenDDS::DCPS::Value::b_

◆ c_

char OpenDDS::DCPS::Value::c_

◆ conversion_preferred_

bool OpenDDS::DCPS::Value::conversion_preferred_

Definition at line 87 of file FilterEvaluator.h.

Referenced by conversion(), convert(), swap(), and Value().

◆ f_

double OpenDDS::DCPS::Value::f_

◆ i_

int OpenDDS::DCPS::Value::i_

◆ l_

ACE_INT64 OpenDDS::DCPS::Value::l_

◆ ld_

ACE_CDR::LongDouble OpenDDS::DCPS::Value::ld_

◆ m_

ACE_UINT64 OpenDDS::DCPS::Value::m_

◆ s_

const char* OpenDDS::DCPS::Value::s_

◆ type_

Type OpenDDS::DCPS::Value::type_

Definition at line 75 of file FilterEvaluator.h.

Referenced by conversion(), convert(), like(), swap(), Value(), and ~Value().

◆ u_

unsigned int OpenDDS::DCPS::Value::u_

The documentation for this struct was generated from the following files: