OpenDDS  Snapshot(2023/04/07-19:43)
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 38 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 581 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 589 of file FilterEvaluator.cpp.

◆ Value() [4/13]

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

Definition at line 593 of file FilterEvaluator.cpp.

◆ Value() [5/13]

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

Definition at line 597 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 621 of file FilterEvaluator.cpp.

References strdup().

623  , conversion_preferred_(conversion_preferred)
624 {}
char * strdup(const char *s)

◆ Value() [10/13]

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

Definition at line 626 of file FilterEvaluator.cpp.

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

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

◆ Value() [11/13]

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

Definition at line 638 of file FilterEvaluator.cpp.

References strdup().

639  : type_(VAL_STRING), s_(ACE_OS::strdup(s.in()))
640  , conversion_preferred_(conversion_preferred)
641 {}
char * strdup(const char *s)

◆ Value() [12/13]

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

Definition at line 643 of file FilterEvaluator.cpp.

References strdup().

644  : type_(VAL_STRING)
645 #ifdef DDS_HAS_WCHAR
646  , s_(ACE_OS::strdup(ACE_Wide_To_Ascii(s.in()).char_rep()))
647 #else
648  , s_(0)
649 #endif
650  , conversion_preferred_(conversion_preferred)
651 {
652 #ifndef DDS_HAS_WCHAR
653  ACE_UNUSED_ARG(s);
654 #endif
655 }
char * strdup(const char *s)

◆ ~Value()

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

◆ Value() [13/13]

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

Definition at line 734 of file FilterEvaluator.cpp.

735  : type_(v.type_), conversion_preferred_(v.conversion_preferred_)
736 {
737  Assign visitor(*this);
738  visit(visitor, v);
739 }

Member Function Documentation

◆ conversion()

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

Definition at line 961 of file FilterEvaluator.cpp.

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

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

962 {
963  if (lhs.type_ == rhs.type_) {
964  return;
965  }
966  bool ok = false;
967  Value& smaller = (lhs.type_ < rhs.type_) ? lhs : rhs;
968  Value& larger = (lhs.type_ < rhs.type_) ? rhs : lhs;
969  if (smaller.conversion_preferred_) {
970  ok = smaller.convert(larger.type_);
971  } else if (larger.conversion_preferred_) {
972  ok = larger.convert(smaller.type_);
973  } else if (smaller.type_ == VAL_CHAR && larger.type_ == VAL_STRING) {
974  ok = smaller.convert(VAL_STRING);
975  } else if (larger.type_ <= VAL_LARGEST_NUMERIC) {
976  ok = smaller.convert(larger.type_);
977  } else if (larger.type_ == VAL_STRING) {
978  if (larger.convert(smaller.type_)) {
979  ok = true;
980  } else {
981  ok = smaller.convert(VAL_STRING);
982  }
983  }
984  if (!ok) {
985  throw std::runtime_error("Types don't match and aren't convertible.");
986  }
987 }
any Value

◆ convert()

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

Definition at line 929 of file FilterEvaluator.cpp.

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

Referenced by conversion().

930 {
931  OPENDDS_STRING asString;
932  if (type_ == VAL_STRING) {
933  asString = s_;
934  } else {
935  std::ostringstream oss;
936  StreamInsert visitor(oss);
937  visit(visitor, *this);
938  asString = oss.str();
939  }
940 
941  Value newval = 0;
942  newval.type_ = t;
943  newval.conversion_preferred_ = false;
944  if (t == VAL_STRING) {
945  newval.s_ = ACE_OS::strdup(asString.c_str());
946  swap(newval);
947  return true;
948  } else {
949  std::istringstream iss(asString);
950  StreamExtract visitor(iss);
951  visit(visitor, newval);
952  if (iss.eof() && !iss.bad()) {
953  swap(newval);
954  return true;
955  }
956  return false;
957  }
958 }
#define OPENDDS_STRING
char * strdup(const char *s)
any Value
void swap(Value &other)

◆ 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 657 of file FilterEvaluator.cpp.

References b_.

657 { return b_; }

◆ get() [4/20]

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

Definition at line 658 of file FilterEvaluator.cpp.

References i_.

658 { return i_; }

◆ get() [5/20]

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

Definition at line 659 of file FilterEvaluator.cpp.

References u_.

659 { return u_; }

◆ get() [6/20]

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

Definition at line 660 of file FilterEvaluator.cpp.

References l_.

660 { return l_; }

◆ get() [7/20]

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

Definition at line 661 of file FilterEvaluator.cpp.

References m_.

661 { return m_; }

◆ get() [8/20]

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

Definition at line 662 of file FilterEvaluator.cpp.

References c_.

662 { return c_; }

◆ get() [9/20]

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

Definition at line 663 of file FilterEvaluator.cpp.

References f_.

663 { return f_; }

◆ get() [10/20]

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

Definition at line 664 of file FilterEvaluator.cpp.

References ld_.

664 { return ld_; }
ACE_CDR::LongDouble ld_

◆ get() [11/20]

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

Definition at line 665 of file FilterEvaluator.cpp.

References s_.

665 { return s_; }

◆ get() [12/20]

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

Definition at line 667 of file FilterEvaluator.cpp.

References b_.

667 { return b_; }

◆ get() [13/20]

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

Definition at line 668 of file FilterEvaluator.cpp.

References i_.

668 { return i_; }

◆ get() [14/20]

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

Definition at line 669 of file FilterEvaluator.cpp.

References u_.

669 { return u_; }

◆ get() [15/20]

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

Definition at line 670 of file FilterEvaluator.cpp.

References l_.

670 { return l_; }

◆ get() [16/20]

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

Definition at line 671 of file FilterEvaluator.cpp.

References m_.

671 { return m_; }

◆ get() [17/20]

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

Definition at line 672 of file FilterEvaluator.cpp.

References c_.

672 { return c_; }

◆ get() [18/20]

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

Definition at line 673 of file FilterEvaluator.cpp.

References f_.

673 { return f_; }

◆ get() [19/20]

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

Definition at line 674 of file FilterEvaluator.cpp.

References ld_.

674 { return ld_; }
ACE_CDR::LongDouble ld_

◆ get() [20/20]

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

Definition at line 675 of file FilterEvaluator.cpp.

References s_.

675 { return s_; }

◆ like()

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

Definition at line 871 of file FilterEvaluator.cpp.

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

872 {
873  if (type_ != VAL_STRING || v.type_ != VAL_STRING) {
874  throw std::runtime_error("'like' operator called on non-string arguments.");
875  }
876  OPENDDS_STRING pattern(v.s_);
877  // escape ? or * in the pattern string so they are not wildcards
878  for (size_t i = pattern.find_first_of("?*"); i < pattern.length();
879  i = pattern.find_first_of("?*", i + 1)) {
880  pattern.insert(i++, 1, '\\');
881  }
882  // translate _ and % wildcards into those used by ACE::wild_match() (?, *)
883  for (size_t i = pattern.find_first_of("_%"); i < pattern.length();
884  i = pattern.find_first_of("_%", i + 1)) {
885  pattern[i] = (pattern[i] == '_') ? '?' : '*';
886  }
887  return ACE::wild_match(s_, pattern.c_str(), true, true);
888 }
#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 861 of file FilterEvaluator.cpp.

References conversion().

862 {
863  Value lhs = *this;
864  Value rhs = v;
865  conversion(lhs, rhs);
866  Modulus visitor(lhs);
867  return visit(visitor, rhs);
868 }
static void conversion(Value &lhs, Value &rhs)
any Value

◆ operator<()

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

Definition at line 851 of file FilterEvaluator.cpp.

References conversion().

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

◆ operator=()

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

Definition at line 742 of file FilterEvaluator.cpp.

References swap().

743 {
744  Value cpy(v);
745  swap(cpy);
746  return *this;
747 }
any Value
void swap(Value &other)

◆ operator==()

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

Definition at line 841 of file FilterEvaluator.cpp.

References conversion().

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

◆ swap()

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

Definition at line 750 of file FilterEvaluator.cpp.

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

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

751 {
752  Value t(v);
753 
754  if (v.type_ == VAL_STRING) {
755  ACE_OS::free((void*)v.s_);
756  }
757 
758  Assign visitor1(v, true);
759  visit(visitor1, *this);
760  if (type_ == VAL_STRING) {
761  s_ = 0;
762  }
763 
764  Assign visitor2(*this, true);
765  visit(visitor2, t);
766  if (t.type_ == VAL_STRING) {
767  t.s_ = 0;
768  }
769 
770  std::swap(conversion_preferred_, v.conversion_preferred_);
771  std::swap(type_, v.type_);
772 }
void free(void *)
any Value
void swap(MessageBlock &lhs, MessageBlock &rhs)

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 88 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 76 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: