SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
Sumant Tambe, Ph.D.
Senior Software Research Engineer and Microsoft MVP
Real-Time Innovations, Inc.
www.rti.com
SILICON VALLEY
10/2/2013 © 2012 RTI 2
Data-Centric Communication Model in DDS
Data Distribution Service
10/2/2013 © 2012 RTI 3
• Data Distribution Service
– Middleware knows the schema
– Messages represent update to data-objects
– Data-Objects identified by a key
– Middleware maintains state of each object
– Objects are cached. Applications can read at leisure
– Smart QoS (Reliability, Ownership, History (per key), Deadline, and 18 more!)
Streaming
Data
Sensors Events
Real-Time
Applications
Enterprise
Applications
Actuators
Data-Centric  Typed All the Way!
10/2/2013 © 2013 RTI 4
Standard
Mapping
Java
C/C++
C#
Type Descriptions
in DDS-XTypes
(IDL, XSD, Java etc.)
Code
Generator
• Types description similar to an OO language
– Primitives, strings, arrays and sequences, maps, structures,
enumerations, aliases (typedefs), unions, modules, etc.
• Type versioning and assignability
• Meta-Data
– Unique ID for each member
– Annotations (like in Java)
– Key/non-key
– Optional/required members
– Sharable/non-sharable
DDS X-Types Standard
• Type System: DDS data objects have a type and obey the rules described
herein
• Language Binding for Object Manipulation
– Generate code when type-descriptions are available at compile-time
– Otherwise, create/inspect objects of any type at run-time
• Language Binding for Type Manipulation
– add/remove/query data members types (think Java reflection)
• Data Representation: Objects can be serialized for file storage and
network transmission
• Type Representation: Types can be serialized for file storage and network
transmission (using TypeObject) 5
Type System
Type
Representation
Language
Binding
Data
Representation
Example
6
Type
Representation
Language
Binding
Data
Representation
IDL: Foo.idl
struct Foo {
string name;
@key long ssn;
@optional string
phone;
};
IDL to C++ Language Mapping:
struct Foo {
std::string name;
int ssn;
std::string * phone;
// ...
};
IDL to CDR:
00000006
68656C6C
6F000000
00000002
Two Faces of DDS
10/2/2013 © 2013 RTI 7
• Application Integration
– Many applications, many programming languages, many
contractors necessitate a common format for sharing types
– IDL serves well
– Related technologies: CORBA Interfaces, schema definitions (DB),
XML document structure (XSD)
• Messaging
– Typically, a single (distributed) application
– Likely developed using a single programming language
– Overall system under single administration
– Data already stored in application data structures
– Just send it from point A to B
– Related technologies: ActiveMQ, JMS
– IDL not so much desirable
IDL may be a Distraction (for messaging apps)
• “… But I already have my headers…”
– Maintaining redundant IDL type descriptions is a burden
– Integrating generated code in app build system could be burdensome
– Must write glue code
• Or sometimes it is an overhead
– Copy data back and forth between app data types and IDL data types
• Application level data structures may not be captured
accurately
– Think XSD (e.g., sequence of choices)
10/2/2013 © 2013 RTI 8
Solution: A Pure C++11 Library-based Approach
Example:
10/2/2013 © 2012 RTI 9
// shape.h
struct ShapeType
{
std::string color;
int x;
int y;
unsigned shapesize;
};
// shape.h
RTI_ADAPT_STRUCT(
ShapeType,
(std::string, color, KEY)
(int, x)
(int, y)
(unsigned, shapesize))
DDSDomainParticipant * participant = ...
GenericDataWriter<ShapeType> shapes_writer(participant, "Square");
for(;;) {
ShapeType shape {“BLUE”, x, y, 30};
shapes_writer.write(shape);
}
Solution: A Pure C++11 Library-based Approach
Example:
10/4/2013 © 2012 RTI 10
// shape.h
struct ShapeType
{
std::string color;
int x;
int y;
unsigned shapesize;
};
// shape.h
RTI_ADAPT_STRUCT(
ShapeType,
(std::string, color, KEY)
(int, x)
(int, y)
(unsigned, shapesize))
@Extensibility(EXTENSIBLE)
struct ShapeType {
@key string color;
long x;
long y;
unsigned long shapesize;
};
Instead
IDL
A substitute for lack of reflection in C++
Read/Take Shapes (note C++11)
10/2/2013 © 2013 RTI 11
class MyShapesListener : public GenericDataReaderListener<ShapeType> {
public:
void on_data_available(GenericDataReader<ShapeType> & dr) override {
std::vector<ShapeType> samples = dr.take();
for (auto const &shape : samples) {
std::cout << “color = " << shape.color << “n”
<< "x = " << shape.x << “n”
<< "y = " << shape.y << “n”
<< "shapesize = " << shape.shapesize << “n”
<< std::endl;
}
}
};
DDSDomainParticipant * participant = ...
MyShapesListener listener;
std::string topic = “Square”;
GenericDataReader<ShapeType> shapes_reader(participant, &listener, topic);
for(;;)
sleep(1);
Slightly Complex Example
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 12
struct VetoTDCHit {
int hit_index;
int pmt_index; // not sent
float pmt_theta;
float pmt_phi;
};
typedef std::list<VetoTDCHit> VetoTDCHits;
struct VetoTruth
{
int sim_event;
VetoTDCHits hits;
};
enum STATUS_FLAGS { NORMAL=0,
ID_MISMATCH=1,
BAD_TIMESTAMP=2 };
struct EventInfo {
VetoTruth truth;
int event_id;
STATUS_FLAGS status;
};
RTI_ADAPT_STRUCT( // same header
VetoTDCHit,
(int, hit_index)
(float, pmt_theta)
(float, pmt_phi))
RTI_ADAPT_STRUCT(
VetoTruth,
(int, sim_event)
(VetoTDCHits, hits))
RTI_ADAPT_ENUM(
STATUS_FLAGS,
(NORMAL, 0)
(ID_MISMATCH, 1)
(BAD_TIMESTAMP, 2))
RTI_ADAPT_STRUCT(
EventInfo,
(VetoTruth, truth)
(int, event_id, KEY)
(TATUS_FLAGS, status))
Equivalent Type at Run-time
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 13
@Extensibility(EXTENSIBLE_EXTENSIBILITY)
enum STATUS_FLAGS {
NORMAL = 0,
ID_MISMATCH = 1,
BAD_TIMESTAMP = 2,
};
@Extensibility(EXTENSIBLE_EXTENSIBILITY)
struct VetoTDCHit {
long hit_index;
float pmt_theta;
float pmt_phi;
};
@Extensibility(EXTENSIBLE_EXTENSIBILITY)
struct VetoTruth {
long sim_event;
sequence<VetoTDCHit> hits;
};
@Extensibility(EXTENSIBLE_EXTENSIBILITY)
struct EventInfo {
VetoTruth truth;
@key long event_id;
STATUS_FLAGS status;
};
Type representation
is binary at runtime
but shown here
using the IDL syntax
for readability
So, How does it work?
• It uses:
– C++11
– Overloading in overdrive!
• SFINAE: Substitution Failure Is Not An Error
– Generic/Generative programming (templates)
– Template meta-programming
– Some (macro) preprocessor tricks
• For code generation
– C++ Standard Library
• tuple, pair, vector, list, set, map, array, type_traits etc.
– Boost
• Fusion, Optional, Variant, and Preprocessor
– TypeCode API
– Dynamic Data API
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 14
What is Supported? (C++ point of view)
• Built-in types, arrays, enumerations
• Nested structs/classes (with public members)
• STL
– string, vector, list, set, map, array, tuple, pair, iterators, etc.
• User-defined/custom containers
– my_special_container_with_iterators
– On-the-fly container adapters (views e.g., boost.Iterators)
• C++11 compilers
– Visual Studio 2013 Preview
– gcc 4.9
– Clang 3.0, 3.2
• In future…
– Raw Pointers, smart pointers
– Classes with public get/set methods?
– Inheritance?
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 15
What is Supported? (IDL point of view)
• Basic types/enumerations/strings
• Arrays
• Sequences of strings/basic types/enumerations
• Bounded sequences/strings
• Structures
• Unions (including cases with defaults, multiple discriminators, and enumerations)
• Sparse Types
• Sequences of sequences (of sequences… and so on…)
• Sequences of structures
• Multidimensional arrays of strings, structures, sequences,…
• Nested structures
• Nested unions
• But, no bit-fields and inheritance, so far…
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 16
Architecture
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 17
Application
GenericDataReader<T>
GenericDataReaderListener<T>
GenericDataWriter<T>
Generic Functions
(MakeTypecode, FillDD, ExtractDD, etc.)
Type-driven access (overloading, template
meta-programming, etc.)
RTI_ADAPT
Macros
TypeCode, Dynamic Data API, DynamicDataTypeSupport
Dynamic Data Type Plugin callbacks and CDR API
DDS Core
Extremely Simplified
DynamicData API
class DDS_TypeCode {};
class DDS_DynamicData
{
public:
explicit DDS_DynamicData(const DDS_TypeCode &) {}
void set_short (int id, int16_t) {}
void set_long (int id, int32_t) {}
void set_longlong (int id, uint64_t) {}
void set_octet (int id, uint8_t) {}
void set_ushort (int id, uint16_t) {}
void set_ulong (int id, uint32_t) {}
void set_ulonglong (int id, uint64_t) {}
void set_float (int id, float) {}
void set_double (int id, double) {}
void set_longdouble(int id, long double) {}
void set_string (int id, const char *) {}
void set_complex (int id, const DDS_DynamicData &) {}
};
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 18
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 19
Overloading for Fundamental Types
void set_value(DDS_DynamicData & d, int id, bool v) {
d.set_bool(id, v); }
void set_value(DDS_DynamicData & d, int id, char v) {
d.set_char(id, v); }
void set_value(DDS_DynamicData & d, int id, int16_t v) {
d.set_short(id, v); }
void set_value(DDS_DynamicData & d, int id, int32_t v) {
d.set_long(id, v); }
void set_value(DDS_DynamicData & d, int id, float v) {
d.set_float(id, v); }
void set_value(DDS_DynamicData & d, int id, double v) {
d.set_double(id, v); }
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 20
Overloading set_value for std::string
void set_value(DDS_DynamicData & d,
int id,
const std::string & str)
{
d.set_string(id, str.c_str());
}
Sequences
(simplified DDS DynamicData API, again)
class DDS_DynamicData
{
public:
void set_boolean_seq (int id, const DDS_BooleanSeq &) {}
void set_long_seq (int id, const DDS_LongSeq &) {}
void set_float_seq (int id, const DDS_FloatSeq &) {}
void set_double_seq (int id, const DDS_DoubleSeq &) {}
void set_longdouble_seq (int id, const DDS_LongDoubleSeq &) {}
};
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 21
• Sequences are wrappers over C-style arrays
• Flexible: May own memory or loan/unloan from the user
– RAII is used when memory is owned
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 22
Overloading for std::vector of primitives
void set_value(DDS_DynamicData & d,
int id,
const std::vector<float> & v)
{
DDS_FloatSeq seq;
seq.loan_contiguous(&v[0], v.size(), v.capacity());
d.set_float_seq(id, seq);
seq.unloan();
}
// and many many more similar looking functions for
// int8_t, int16_t, int32_t, int64_t, char, double, ...
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 23
set_value Template for std::vector of primitives
template <class T>
void set_value(DDS_DynamicData & d,
int id,
const std::vector<T> & v)
{
typename DynamicDataSeqTraits<T>::type seq;
seq.loan_contiguous(&v[0], v.size(), v.capacity());
typename DynamicDataSeqTraits<T>::SetSeqFuncPtr fn =
DynamicDataSeqTraits<T>::set_seq_func_ptr;
d.*fn(id, seq);
seq.unloan();
}
• One template for all vectors of primitives
• Traits to get the function pointer
• Traits written using macros!
• Isn’t that just overloading and static method dispatch? . . . Yes it is!
Static
method
dispatch
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 24
But set_value[T=bool] is outright wrong!
template <class T>
void set_value(DDS_DynamicData & d,
int id,
const std::vector<T> & v)
{
typename DynamicDataSeqTraits<T>::type seq;
seq.loan_contiguous(&v[0], v.size(), v.capacity());
typename DynamicDataSeqTraits<T>::SetSeqFuncPtr fn =
DynamicDataSeqTraits<T>::set_seq_func_ptr;
d.*fn(id, seq);
seq.unloan();
}
std::vector<bool>
layout incompatible
• std::vector<bool> is often a space-efficient data structure
• Each element occupies a single bit instead of a single byte
• Does not follow many other std::vector invariants
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 25
Add std::vector<bool> overload of set_value
template <class T>
void set_value(DDS_DynamicData & d,
int id,
const std::vector<T> & v) {
typename DynamicDataSeqTraits<T>::type seq;
seq.loan_contiguous(&v[0], v.size(), v.size());
typename DynamicDataSeqTraits<T>::SetSeqFuncPtr fn =
DynamicDataSeqTraits<T>::set_seq_func_ptr;
d.*fn(id, seq);
seq.unloan();
}
void set_value(DDS_DynamicData & d,
int id,
const std::vector<bool> & v) {
DDS_BooleanSeq seq;
seq.ensure_length(v.size(), v.size());
std::copy(begin(v), end(v), &seq[0]);
d.set_boolean_seq(id, seq);
}
Overload for Classic Enumerations
• C++03 enumerations implicitly convert to an integer
– User C++11’s type-safe enums if you don’t want that
• The following overload works ... for now!
• set_value(DDS_DynamicData &, int id, int32_t)
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 26
enums go here
Overload for user-defined structs: “Foo”
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 27
template <class T>
void set_value(DDS_DynamicData & d,
int id,
const T & t)
{
DDS_DynamicData inner;
// Use boost.fusion to iterate over the public members of T
// and use set_value recursively to populate the inner object.
// Effectively equivalent to
set_value(inner, 0, at<0>(t));
set_value(inner, 1, at<1>(t));
set_value(inner, 2, at<2>(t)); // and so on...
d.set_complex(id, inner);
}
Enumerations are user-defined types too!
• Addition of the template for Foo breaks enumerations
• Solution:
– Function Overloading Based on Arbitrary Properties of
Types
– Powered by SFINAE!
• Substitution Failure Is Not An Error
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 28
template <class T>
void set_value(DDS_DynamicData & d,
int id,
const T & t);
All enums and user-
defined structs resolve to
this overload
(that’s not what we want)
A SFINAE Primer
• Instantiating a function template is a two-phase process
– Deduce template arguments
– Substitute the deduced type in all occurrences of the template
parameter
• If the substitution process leads to an invalid type,
argument deduction fails
• The function is removed from the overload resolution set
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 29
int negate(int i) { return -i; }
template <class F>
typename F::result_type
negate(const F& f) { return -f(); }
negate(1);
Function Enablers and Disablers
• enable_if<true> keeps the template instantiation in the overload set
• enable_if<false> removes the template instantiation from the overload
set
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 30
template <bool B, class T = void>
struct enable_if {
typedef T type;
};
template <class T>
struct enable_if<false, T> {};
template <class T>
typename enable_if<is_arithmetic<T>::value, T>::type
foo(T t);
template <class T>
T bar (T t,
typename enable_if<is_arithmetic<T>::value>::type* = 0);
Using enable_if with type_traits
• enable_if combined with type_traits is very powerful
• Many type_traits are implemented using compiler intrinsics
– Think of it as compile-time reflection in library form
– E.g., is_union, is_pod, is_enum, any many many more
– C++11 type_traits library is portable
10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 31
template <class T>
void set_value(DDS_DynamicData & d,
int id,
const T & t,
typename enable_if<std::is_enum<T>::value>::type * = 0);
template <class T>
void set_value(DDS_DynamicData & d,
int id,
const T & t,
typename enable_if<std::is_class<T>::value>::type * = 0);
Recap set_value overloads so far
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 32
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &);[T=fundamental]
2
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 3
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<std::is_enum<T>::value>::type * = 0);
4
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<std::is_class<T>::value>::type * = 0);
5
• Works with
– 18 fundamental types, std::vector of those, std::vector<bool>, scalar
enumerations, and scalar user-defined structs.
• No match for
– std::vector<USER-DEFINED-STRUCTS>
More overloads
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 33
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
disable_if<is_fundamental<T>::value>::type * = 0);
3
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 4
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
6
• Works with
– std::vector<USER-DEFINED-STRUCT>, std::vector<bool>, scalar enumerations, scalar user-defined structs, 18
fundamental types, std::vector of those
• Resolves incorrectly for std::vector<ENUMS>
– Resolves to overload #3 but that’s wrong because enums are not fundamental types
More overloads!
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 34
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
disable_if<is_fundamental<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
• std::vector<ENUMS> does not work due to ambiguity
• Overload #3 and #4 are both viable for std::vector<ENUMS>
More overloads!
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 35
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_class<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
• Support built-in arrays
– Without array-specific overloads arrays map to the bool overload!
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 36
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_class<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0);
8
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0);
9
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0);
10
set_value Overloads for built-in arrays
Overloads for std::vector<T[N]> ?
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 37
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_class<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0);
8
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0);
9
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0);
10
Works for vector
of structs but not
for vector of
built-in arrays
Overloads for std::vector<T[N]>
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 38
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
disable_if<is_fundamental<T>::value ||
is_enum<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0);
8
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0);
9
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0);
10
Works for vector
of structs/built-in
arrays/nested
vectors
The Overloads are Mutually Recursive
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 39
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
disable_if<is_fundamental<T>::value ||
is_enum<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0);
8
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0);
9
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0);
10
May call
The Overloads are Mutually Recursive
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 40
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
disable_if<is_fundamental<T>::value ||
is_enum<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0);
8
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0);
9
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0);
10
Works for
Multidimensional
array or array of
complex types
Overloading for Other STL Containers!
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 41
Overloads #
void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
2
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_class<T>::value>::type * = 0);
3
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &,
enable_if<is_enum<T>::value>::type * = 0);
4
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_class<T>::value>::type * = 0);
7
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0);
8
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0);
9
template <class T, unsigned N>
void set_value(DDS_DynamicData &, int, const T(&arr)[N],
typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0);
10
What about
standard list, set,
deque, unordered,
etc.?
Overloading for Other STL Containers!
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 42
template <class T>
struct is_container : std::false_type {};
template <class T, class Alloc>
struct is_container<std::vector<T, Alloc>> : std::true_type {};
template <class T, class Alloc>
struct is_container<std::list<T, Alloc>> : std::true_type {};
template <class T, class Comp, class Alloc>
struct is_container<std::set<T, Comp, Alloc>> : std::true_type {};
template <class Key, class Value, class Comp, class Alloc>
struct is_container<std::map<Key, Value, Comp, Alloc>> : std::true_type {};
// and few more ...
Overloading for Other STL Containers!
10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 43
Overloads #
template <class T>
void set_value(DDS_DynamicData &, int, const std::vector<T> &
enable_if<is_fundamental<T>::value>::type * = 0);
1
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename disable_if<!is_container<T>::value ||
std::is_fundamental<typename T::value_type>::value ||
std::is_enum<typename T::value_type>::value >::type * = 0)
2
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_container<T>::value &&
(is_fundamental<typename T::value_type>::value ||
std::is_enum<typename T::value_type>::value) &&
(is_vector<T>::value?
is_bool_or_enum<typename T::value_type>::value :
true)>::type * = 0);
3
void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 4
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<!is_container<T>::value &&
is_class<T>::value>::type * = 0);
5
template <class T>
void set_value(DDS_DynamicData &, int, const T &,
typename enable_if<is_enum<T>::value>::type * = 0);
6
Overloads for fundamental scalar types and built-in arrays are not shown
T is a std container
of primitives but
not vector
<primitives except
(bool & enums)>
T is a std container of
complex type
Scalar complex type
(Foo)
Scalar Enums
vector<fundamental>
Using set_value overloads with Boost.Fusion
struct SetValue {
SetValue(DDS_DynamicData &dd);
// ...
template <typename T>
void operator()(T& t) const {
set_value(dd, ++id, t);
}
};
ShapeType shape(“BLUE”, x, y, 30);
DDS_DynamicData dd(get_typecode<ShapeType>());
boost::fusion::for_each(shape, SetValue(dd));
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 44
// shape.h
struct ShapeType
{
std::string color;
int x;
int y;
unsigned shapesize;
};
// shape.h
RTI_ADAPT_STRUCT(
ShapeType,
(std::string, color, KEY)
(int, x)
(int, y)
(unsigned, shapesize))
More Info
• OMG DDS
– http://portals.omg.org/dds/
• RTI Connext™ DDS
– http://www.rti.com/products/dds/
• Example Code
– https://cpptruths.googlecode.com/svn/trunk/cpp
0x/overloading-overdrive.cpp
10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 45
Thank you!
© 2012 RTI • COMPANY CONFIDENTIAL

Contenu connexe

Tendances

Apache Spark Machine Learning
Apache Spark Machine LearningApache Spark Machine Learning
Apache Spark Machine LearningCarol McDonald
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are DatabasesMartin Odersky
 
Performance and predictability (1)
Performance and predictability (1)Performance and predictability (1)
Performance and predictability (1)RichardWarburton
 
Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)Chris Richardson
 
Introduction to Machine Learning with Spark
Introduction to Machine Learning with SparkIntroduction to Machine Learning with Spark
Introduction to Machine Learning with Sparkdatamantra
 
Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Databricks
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David SzakallasDatabricks
 
Deep Anomaly Detection from Research to Production Leveraging Spark and Tens...
 Deep Anomaly Detection from Research to Production Leveraging Spark and Tens... Deep Anomaly Detection from Research to Production Leveraging Spark and Tens...
Deep Anomaly Detection from Research to Production Leveraging Spark and Tens...Databricks
 
Statistical Learning and Text Classification with NLTK and scikit-learn
Statistical Learning and Text Classification with NLTK and scikit-learnStatistical Learning and Text Classification with NLTK and scikit-learn
Statistical Learning and Text Classification with NLTK and scikit-learnOlivier Grisel
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellDatabricks
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overviewstasimus
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInVitaly Gordon
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Jonathan Felch
 
Survey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and AnalyticsSurvey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and AnalyticsYannick Pouliot
 
Toub parallelism tour_oct2009
Toub parallelism tour_oct2009Toub parallelism tour_oct2009
Toub parallelism tour_oct2009nkaluva
 
VelocityGraph Introduction
VelocityGraph IntroductionVelocityGraph Introduction
VelocityGraph IntroductionMats Persson
 

Tendances (20)

Apache Spark Machine Learning
Apache Spark Machine LearningApache Spark Machine Learning
Apache Spark Machine Learning
 
Compilers Are Databases
Compilers Are DatabasesCompilers Are Databases
Compilers Are Databases
 
Core concepts of C++
Core concepts of C++  Core concepts of C++
Core concepts of C++
 
Performance and predictability (1)
Performance and predictability (1)Performance and predictability (1)
Performance and predictability (1)
 
Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)Map, flatmap and reduce are your new best friends (javaone, svcc)
Map, flatmap and reduce are your new best friends (javaone, svcc)
 
Dplyr packages
Dplyr packagesDplyr packages
Dplyr packages
 
Introduction to Machine Learning with Spark
Introduction to Machine Learning with SparkIntroduction to Machine Learning with Spark
Introduction to Machine Learning with Spark
 
Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David Szakallas
 
Deep Anomaly Detection from Research to Production Leveraging Spark and Tens...
 Deep Anomaly Detection from Research to Production Leveraging Spark and Tens... Deep Anomaly Detection from Research to Production Leveraging Spark and Tens...
Deep Anomaly Detection from Research to Production Leveraging Spark and Tens...
 
Statistical Learning and Text Classification with NLTK and scikit-learn
Statistical Learning and Text Classification with NLTK and scikit-learnStatistical Learning and Text Classification with NLTK and scikit-learn
Statistical Learning and Text Classification with NLTK and scikit-learn
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
MATLAB and HDF-EOS
MATLAB and HDF-EOSMATLAB and HDF-EOS
MATLAB and HDF-EOS
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
Survey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and AnalyticsSurvey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and Analytics
 
Toub parallelism tour_oct2009
Toub parallelism tour_oct2009Toub parallelism tour_oct2009
Toub parallelism tour_oct2009
 
Scalax
ScalaxScalax
Scalax
 
VelocityGraph Introduction
VelocityGraph IntroductionVelocityGraph Introduction
VelocityGraph Introduction
 

En vedette

C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 Sumant Tambe
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Sumant Tambe
 
Reactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and RxReactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and RxSumant Tambe
 
C++ Generators and Property-based Testing
C++ Generators and Property-based TestingC++ Generators and Property-based Testing
C++ Generators and Property-based TestingSumant Tambe
 
O caml2014 leroy-slides
O caml2014 leroy-slidesO caml2014 leroy-slides
O caml2014 leroy-slidesOCaml
 
Getting Started with DDS in C++, Java and Scala
Getting Started with DDS in C++, Java and ScalaGetting Started with DDS in C++, Java and Scala
Getting Started with DDS in C++, Java and ScalaAngelo Corsaro
 
The Present and Future of DDS
The Present and Future of DDSThe Present and Future of DDS
The Present and Future of DDSAngelo Corsaro
 

En vedette (8)

C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
Reactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and RxReactive Stream Processing in Industrial IoT using DDS and Rx
Reactive Stream Processing in Industrial IoT using DDS and Rx
 
C++ Generators and Property-based Testing
C++ Generators and Property-based TestingC++ Generators and Property-based Testing
C++ Generators and Property-based Testing
 
O caml2014 leroy-slides
O caml2014 leroy-slidesO caml2014 leroy-slides
O caml2014 leroy-slides
 
Getting Started with DDS in C++, Java and Scala
Getting Started with DDS in C++, Java and ScalaGetting Started with DDS in C++, Java and Scala
Getting Started with DDS in C++, Java and Scala
 
The Present and Future of DDS
The Present and Future of DDSThe Present and Future of DDS
The Present and Future of DDS
 
Deep C
Deep CDeep C
Deep C
 

Similaire à Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS

Extensible and Dynamic Topic Types For DDS (out of date)
Extensible and Dynamic Topic Types For DDS (out of date)Extensible and Dynamic Topic Types For DDS (out of date)
Extensible and Dynamic Topic Types For DDS (out of date)Rick Warren
 
mm-ADT: A Multi-Model Abstract Data Type
mm-ADT: A Multi-Model Abstract Data Typemm-ADT: A Multi-Model Abstract Data Type
mm-ADT: A Multi-Model Abstract Data TypeMarko Rodriguez
 
DDS Advanced Tutorial - OMG June 2013 Berlin Meeting
DDS Advanced Tutorial - OMG June 2013 Berlin MeetingDDS Advanced Tutorial - OMG June 2013 Berlin Meeting
DDS Advanced Tutorial - OMG June 2013 Berlin MeetingJaime Martin Losa
 
7 DDS Innovations to Improve your Next Distributed System
7 DDS Innovations to Improve your Next Distributed System7 DDS Innovations to Improve your Next Distributed System
7 DDS Innovations to Improve your Next Distributed SystemReal-Time Innovations (RTI)
 
DDS Programming with IDL to C++11 tutorial
DDS Programming with IDL to C++11 tutorialDDS Programming with IDL to C++11 tutorial
DDS Programming with IDL to C++11 tutorialRemedy IT
 
Distributed Systems: How to connect your real-time applications
Distributed Systems: How to connect your real-time applicationsDistributed Systems: How to connect your real-time applications
Distributed Systems: How to connect your real-time applicationsJaime Martin Losa
 
DFDL and Apache Daffodil(tm) Overview from Owl Cyber Defense
DFDL and Apache Daffodil(tm) Overview from Owl Cyber DefenseDFDL and Apache Daffodil(tm) Overview from Owl Cyber Defense
DFDL and Apache Daffodil(tm) Overview from Owl Cyber DefenseMike Beckerle
 
SolidSource Portfolio
SolidSource PortfolioSolidSource Portfolio
SolidSource PortfolioLucian Voinea
 
DDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxxDDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxxAngelo Corsaro
 
Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++Sumant Tambe
 
Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...
Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...
Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...IncQuery Labs
 
IoT Protocols Integration with Vortex Gateway
IoT Protocols Integration with Vortex GatewayIoT Protocols Integration with Vortex Gateway
IoT Protocols Integration with Vortex GatewayAngelo Corsaro
 
Resume_Dimitri_Dey_LTE_Android_Gmail
Resume_Dimitri_Dey_LTE_Android_GmailResume_Dimitri_Dey_LTE_Android_Gmail
Resume_Dimitri_Dey_LTE_Android_GmailDimitri Dey
 
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital.AI
 
Distributed Algorithms with DDS
Distributed Algorithms with DDSDistributed Algorithms with DDS
Distributed Algorithms with DDSAngelo Corsaro
 
Reactive Data Centric Architectures with DDS
Reactive Data Centric Architectures with DDSReactive Data Centric Architectures with DDS
Reactive Data Centric Architectures with DDSAngelo Corsaro
 

Similaire à Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS (20)

DDS ISO C++ PSM
DDS ISO C++ PSMDDS ISO C++ PSM
DDS ISO C++ PSM
 
Extensible and Dynamic Topic Types For DDS (out of date)
Extensible and Dynamic Topic Types For DDS (out of date)Extensible and Dynamic Topic Types For DDS (out of date)
Extensible and Dynamic Topic Types For DDS (out of date)
 
mm-ADT: A Multi-Model Abstract Data Type
mm-ADT: A Multi-Model Abstract Data Typemm-ADT: A Multi-Model Abstract Data Type
mm-ADT: A Multi-Model Abstract Data Type
 
DDS Advanced Tutorial - OMG June 2013 Berlin Meeting
DDS Advanced Tutorial - OMG June 2013 Berlin MeetingDDS Advanced Tutorial - OMG June 2013 Berlin Meeting
DDS Advanced Tutorial - OMG June 2013 Berlin Meeting
 
7 DDS Innovations to Improve your Next Distributed System
7 DDS Innovations to Improve your Next Distributed System7 DDS Innovations to Improve your Next Distributed System
7 DDS Innovations to Improve your Next Distributed System
 
DDS Programming with IDL to C++11 tutorial
DDS Programming with IDL to C++11 tutorialDDS Programming with IDL to C++11 tutorial
DDS Programming with IDL to C++11 tutorial
 
Distributed Systems: How to connect your real-time applications
Distributed Systems: How to connect your real-time applicationsDistributed Systems: How to connect your real-time applications
Distributed Systems: How to connect your real-time applications
 
DFDL and Apache Daffodil(tm) Overview from Owl Cyber Defense
DFDL and Apache Daffodil(tm) Overview from Owl Cyber DefenseDFDL and Apache Daffodil(tm) Overview from Owl Cyber Defense
DFDL and Apache Daffodil(tm) Overview from Owl Cyber Defense
 
SolidSource Portfolio
SolidSource PortfolioSolidSource Portfolio
SolidSource Portfolio
 
DDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxxDDS-PSM-Cxx and simd-cxx
DDS-PSM-Cxx and simd-cxx
 
Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++
 
Overview of the DDS-XRCE specification
Overview of the DDS-XRCE specificationOverview of the DDS-XRCE specification
Overview of the DDS-XRCE specification
 
Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...
Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...
Introducing the New MagicDraw Plug-In for RTI Connext DDS: Industrial IoT Mee...
 
IoT Protocols Integration with Vortex Gateway
IoT Protocols Integration with Vortex GatewayIoT Protocols Integration with Vortex Gateway
IoT Protocols Integration with Vortex Gateway
 
Resume_Dimitri_Dey_LTE_Android_Gmail
Resume_Dimitri_Dey_LTE_Android_GmailResume_Dimitri_Dey_LTE_Android_Gmail
Resume_Dimitri_Dey_LTE_Android_Gmail
 
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
 
Scam 08
Scam 08Scam 08
Scam 08
 
Sw Software Design
Sw Software DesignSw Software Design
Sw Software Design
 
Distributed Algorithms with DDS
Distributed Algorithms with DDSDistributed Algorithms with DDS
Distributed Algorithms with DDS
 
Reactive Data Centric Architectures with DDS
Reactive Data Centric Architectures with DDSReactive Data Centric Architectures with DDS
Reactive Data Centric Architectures with DDS
 

Plus de Sumant Tambe

Kafka tiered-storage-meetup-2022-final-presented
Kafka tiered-storage-meetup-2022-final-presentedKafka tiered-storage-meetup-2022-final-presented
Kafka tiered-storage-meetup-2022-final-presentedSumant Tambe
 
Tuning kafka pipelines
Tuning kafka pipelinesTuning kafka pipelines
Tuning kafka pipelinesSumant Tambe
 
New Tools for a More Functional C++
New Tools for a More Functional C++New Tools for a More Functional C++
New Tools for a More Functional C++Sumant Tambe
 
RPC over DDS Beta 1
RPC over DDS Beta 1RPC over DDS Beta 1
RPC over DDS Beta 1Sumant Tambe
 
Remote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJSRemote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJSSumant Tambe
 
Reactive Stream Processing for Data-centric Publish/Subscribe
Reactive Stream Processing for Data-centric Publish/SubscribeReactive Stream Processing for Data-centric Publish/Subscribe
Reactive Stream Processing for Data-centric Publish/SubscribeSumant Tambe
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
 
An Extensible Architecture for Avionics Sensor Health Assessment Using DDS
An Extensible Architecture for Avionics Sensor Health Assessment Using DDSAn Extensible Architecture for Avionics Sensor Health Assessment Using DDS
An Extensible Architecture for Avionics Sensor Health Assessment Using DDSSumant Tambe
 
Communication Patterns Using Data-Centric Publish/Subscribe
Communication Patterns Using Data-Centric Publish/SubscribeCommunication Patterns Using Data-Centric Publish/Subscribe
Communication Patterns Using Data-Centric Publish/SubscribeSumant Tambe
 
Retargeting Embedded Software Stack for Many-Core Systems
Retargeting Embedded Software Stack for Many-Core SystemsRetargeting Embedded Software Stack for Many-Core Systems
Retargeting Embedded Software Stack for Many-Core SystemsSumant Tambe
 
Ph.D. Dissertation
Ph.D. DissertationPh.D. Dissertation
Ph.D. DissertationSumant Tambe
 
Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Sumant Tambe
 

Plus de Sumant Tambe (13)

Kafka tiered-storage-meetup-2022-final-presented
Kafka tiered-storage-meetup-2022-final-presentedKafka tiered-storage-meetup-2022-final-presented
Kafka tiered-storage-meetup-2022-final-presented
 
Tuning kafka pipelines
Tuning kafka pipelinesTuning kafka pipelines
Tuning kafka pipelines
 
New Tools for a More Functional C++
New Tools for a More Functional C++New Tools for a More Functional C++
New Tools for a More Functional C++
 
C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
 
RPC over DDS Beta 1
RPC over DDS Beta 1RPC over DDS Beta 1
RPC over DDS Beta 1
 
Remote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJSRemote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJS
 
Reactive Stream Processing for Data-centric Publish/Subscribe
Reactive Stream Processing for Data-centric Publish/SubscribeReactive Stream Processing for Data-centric Publish/Subscribe
Reactive Stream Processing for Data-centric Publish/Subscribe
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
An Extensible Architecture for Avionics Sensor Health Assessment Using DDS
An Extensible Architecture for Avionics Sensor Health Assessment Using DDSAn Extensible Architecture for Avionics Sensor Health Assessment Using DDS
An Extensible Architecture for Avionics Sensor Health Assessment Using DDS
 
Communication Patterns Using Data-Centric Publish/Subscribe
Communication Patterns Using Data-Centric Publish/SubscribeCommunication Patterns Using Data-Centric Publish/Subscribe
Communication Patterns Using Data-Centric Publish/Subscribe
 
Retargeting Embedded Software Stack for Many-Core Systems
Retargeting Embedded Software Stack for Many-Core SystemsRetargeting Embedded Software Stack for Many-Core Systems
Retargeting Embedded Software Stack for Many-Core Systems
 
Ph.D. Dissertation
Ph.D. DissertationPh.D. Dissertation
Ph.D. Dissertation
 
Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)
 

Dernier

Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 

Dernier (20)

20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 

Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS

  • 1. Sumant Tambe, Ph.D. Senior Software Research Engineer and Microsoft MVP Real-Time Innovations, Inc. www.rti.com SILICON VALLEY
  • 2. 10/2/2013 © 2012 RTI 2 Data-Centric Communication Model in DDS
  • 3. Data Distribution Service 10/2/2013 © 2012 RTI 3 • Data Distribution Service – Middleware knows the schema – Messages represent update to data-objects – Data-Objects identified by a key – Middleware maintains state of each object – Objects are cached. Applications can read at leisure – Smart QoS (Reliability, Ownership, History (per key), Deadline, and 18 more!) Streaming Data Sensors Events Real-Time Applications Enterprise Applications Actuators
  • 4. Data-Centric  Typed All the Way! 10/2/2013 © 2013 RTI 4 Standard Mapping Java C/C++ C# Type Descriptions in DDS-XTypes (IDL, XSD, Java etc.) Code Generator • Types description similar to an OO language – Primitives, strings, arrays and sequences, maps, structures, enumerations, aliases (typedefs), unions, modules, etc. • Type versioning and assignability • Meta-Data – Unique ID for each member – Annotations (like in Java) – Key/non-key – Optional/required members – Sharable/non-sharable
  • 5. DDS X-Types Standard • Type System: DDS data objects have a type and obey the rules described herein • Language Binding for Object Manipulation – Generate code when type-descriptions are available at compile-time – Otherwise, create/inspect objects of any type at run-time • Language Binding for Type Manipulation – add/remove/query data members types (think Java reflection) • Data Representation: Objects can be serialized for file storage and network transmission • Type Representation: Types can be serialized for file storage and network transmission (using TypeObject) 5 Type System Type Representation Language Binding Data Representation
  • 6. Example 6 Type Representation Language Binding Data Representation IDL: Foo.idl struct Foo { string name; @key long ssn; @optional string phone; }; IDL to C++ Language Mapping: struct Foo { std::string name; int ssn; std::string * phone; // ... }; IDL to CDR: 00000006 68656C6C 6F000000 00000002
  • 7. Two Faces of DDS 10/2/2013 © 2013 RTI 7 • Application Integration – Many applications, many programming languages, many contractors necessitate a common format for sharing types – IDL serves well – Related technologies: CORBA Interfaces, schema definitions (DB), XML document structure (XSD) • Messaging – Typically, a single (distributed) application – Likely developed using a single programming language – Overall system under single administration – Data already stored in application data structures – Just send it from point A to B – Related technologies: ActiveMQ, JMS – IDL not so much desirable
  • 8. IDL may be a Distraction (for messaging apps) • “… But I already have my headers…” – Maintaining redundant IDL type descriptions is a burden – Integrating generated code in app build system could be burdensome – Must write glue code • Or sometimes it is an overhead – Copy data back and forth between app data types and IDL data types • Application level data structures may not be captured accurately – Think XSD (e.g., sequence of choices) 10/2/2013 © 2013 RTI 8
  • 9. Solution: A Pure C++11 Library-based Approach Example: 10/2/2013 © 2012 RTI 9 // shape.h struct ShapeType { std::string color; int x; int y; unsigned shapesize; }; // shape.h RTI_ADAPT_STRUCT( ShapeType, (std::string, color, KEY) (int, x) (int, y) (unsigned, shapesize)) DDSDomainParticipant * participant = ... GenericDataWriter<ShapeType> shapes_writer(participant, "Square"); for(;;) { ShapeType shape {“BLUE”, x, y, 30}; shapes_writer.write(shape); }
  • 10. Solution: A Pure C++11 Library-based Approach Example: 10/4/2013 © 2012 RTI 10 // shape.h struct ShapeType { std::string color; int x; int y; unsigned shapesize; }; // shape.h RTI_ADAPT_STRUCT( ShapeType, (std::string, color, KEY) (int, x) (int, y) (unsigned, shapesize)) @Extensibility(EXTENSIBLE) struct ShapeType { @key string color; long x; long y; unsigned long shapesize; }; Instead IDL A substitute for lack of reflection in C++
  • 11. Read/Take Shapes (note C++11) 10/2/2013 © 2013 RTI 11 class MyShapesListener : public GenericDataReaderListener<ShapeType> { public: void on_data_available(GenericDataReader<ShapeType> & dr) override { std::vector<ShapeType> samples = dr.take(); for (auto const &shape : samples) { std::cout << “color = " << shape.color << “n” << "x = " << shape.x << “n” << "y = " << shape.y << “n” << "shapesize = " << shape.shapesize << “n” << std::endl; } } }; DDSDomainParticipant * participant = ... MyShapesListener listener; std::string topic = “Square”; GenericDataReader<ShapeType> shapes_reader(participant, &listener, topic); for(;;) sleep(1);
  • 12. Slightly Complex Example 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 12 struct VetoTDCHit { int hit_index; int pmt_index; // not sent float pmt_theta; float pmt_phi; }; typedef std::list<VetoTDCHit> VetoTDCHits; struct VetoTruth { int sim_event; VetoTDCHits hits; }; enum STATUS_FLAGS { NORMAL=0, ID_MISMATCH=1, BAD_TIMESTAMP=2 }; struct EventInfo { VetoTruth truth; int event_id; STATUS_FLAGS status; }; RTI_ADAPT_STRUCT( // same header VetoTDCHit, (int, hit_index) (float, pmt_theta) (float, pmt_phi)) RTI_ADAPT_STRUCT( VetoTruth, (int, sim_event) (VetoTDCHits, hits)) RTI_ADAPT_ENUM( STATUS_FLAGS, (NORMAL, 0) (ID_MISMATCH, 1) (BAD_TIMESTAMP, 2)) RTI_ADAPT_STRUCT( EventInfo, (VetoTruth, truth) (int, event_id, KEY) (TATUS_FLAGS, status))
  • 13. Equivalent Type at Run-time 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 13 @Extensibility(EXTENSIBLE_EXTENSIBILITY) enum STATUS_FLAGS { NORMAL = 0, ID_MISMATCH = 1, BAD_TIMESTAMP = 2, }; @Extensibility(EXTENSIBLE_EXTENSIBILITY) struct VetoTDCHit { long hit_index; float pmt_theta; float pmt_phi; }; @Extensibility(EXTENSIBLE_EXTENSIBILITY) struct VetoTruth { long sim_event; sequence<VetoTDCHit> hits; }; @Extensibility(EXTENSIBLE_EXTENSIBILITY) struct EventInfo { VetoTruth truth; @key long event_id; STATUS_FLAGS status; }; Type representation is binary at runtime but shown here using the IDL syntax for readability
  • 14. So, How does it work? • It uses: – C++11 – Overloading in overdrive! • SFINAE: Substitution Failure Is Not An Error – Generic/Generative programming (templates) – Template meta-programming – Some (macro) preprocessor tricks • For code generation – C++ Standard Library • tuple, pair, vector, list, set, map, array, type_traits etc. – Boost • Fusion, Optional, Variant, and Preprocessor – TypeCode API – Dynamic Data API 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 14
  • 15. What is Supported? (C++ point of view) • Built-in types, arrays, enumerations • Nested structs/classes (with public members) • STL – string, vector, list, set, map, array, tuple, pair, iterators, etc. • User-defined/custom containers – my_special_container_with_iterators – On-the-fly container adapters (views e.g., boost.Iterators) • C++11 compilers – Visual Studio 2013 Preview – gcc 4.9 – Clang 3.0, 3.2 • In future… – Raw Pointers, smart pointers – Classes with public get/set methods? – Inheritance? 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 15
  • 16. What is Supported? (IDL point of view) • Basic types/enumerations/strings • Arrays • Sequences of strings/basic types/enumerations • Bounded sequences/strings • Structures • Unions (including cases with defaults, multiple discriminators, and enumerations) • Sparse Types • Sequences of sequences (of sequences… and so on…) • Sequences of structures • Multidimensional arrays of strings, structures, sequences,… • Nested structures • Nested unions • But, no bit-fields and inheritance, so far… 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 16
  • 17. Architecture 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 17 Application GenericDataReader<T> GenericDataReaderListener<T> GenericDataWriter<T> Generic Functions (MakeTypecode, FillDD, ExtractDD, etc.) Type-driven access (overloading, template meta-programming, etc.) RTI_ADAPT Macros TypeCode, Dynamic Data API, DynamicDataTypeSupport Dynamic Data Type Plugin callbacks and CDR API DDS Core
  • 18. Extremely Simplified DynamicData API class DDS_TypeCode {}; class DDS_DynamicData { public: explicit DDS_DynamicData(const DDS_TypeCode &) {} void set_short (int id, int16_t) {} void set_long (int id, int32_t) {} void set_longlong (int id, uint64_t) {} void set_octet (int id, uint8_t) {} void set_ushort (int id, uint16_t) {} void set_ulong (int id, uint32_t) {} void set_ulonglong (int id, uint64_t) {} void set_float (int id, float) {} void set_double (int id, double) {} void set_longdouble(int id, long double) {} void set_string (int id, const char *) {} void set_complex (int id, const DDS_DynamicData &) {} }; 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 18
  • 19. 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 19 Overloading for Fundamental Types void set_value(DDS_DynamicData & d, int id, bool v) { d.set_bool(id, v); } void set_value(DDS_DynamicData & d, int id, char v) { d.set_char(id, v); } void set_value(DDS_DynamicData & d, int id, int16_t v) { d.set_short(id, v); } void set_value(DDS_DynamicData & d, int id, int32_t v) { d.set_long(id, v); } void set_value(DDS_DynamicData & d, int id, float v) { d.set_float(id, v); } void set_value(DDS_DynamicData & d, int id, double v) { d.set_double(id, v); }
  • 20. 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 20 Overloading set_value for std::string void set_value(DDS_DynamicData & d, int id, const std::string & str) { d.set_string(id, str.c_str()); }
  • 21. Sequences (simplified DDS DynamicData API, again) class DDS_DynamicData { public: void set_boolean_seq (int id, const DDS_BooleanSeq &) {} void set_long_seq (int id, const DDS_LongSeq &) {} void set_float_seq (int id, const DDS_FloatSeq &) {} void set_double_seq (int id, const DDS_DoubleSeq &) {} void set_longdouble_seq (int id, const DDS_LongDoubleSeq &) {} }; 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 21 • Sequences are wrappers over C-style arrays • Flexible: May own memory or loan/unloan from the user – RAII is used when memory is owned
  • 22. 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 22 Overloading for std::vector of primitives void set_value(DDS_DynamicData & d, int id, const std::vector<float> & v) { DDS_FloatSeq seq; seq.loan_contiguous(&v[0], v.size(), v.capacity()); d.set_float_seq(id, seq); seq.unloan(); } // and many many more similar looking functions for // int8_t, int16_t, int32_t, int64_t, char, double, ...
  • 23. 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 23 set_value Template for std::vector of primitives template <class T> void set_value(DDS_DynamicData & d, int id, const std::vector<T> & v) { typename DynamicDataSeqTraits<T>::type seq; seq.loan_contiguous(&v[0], v.size(), v.capacity()); typename DynamicDataSeqTraits<T>::SetSeqFuncPtr fn = DynamicDataSeqTraits<T>::set_seq_func_ptr; d.*fn(id, seq); seq.unloan(); } • One template for all vectors of primitives • Traits to get the function pointer • Traits written using macros! • Isn’t that just overloading and static method dispatch? . . . Yes it is! Static method dispatch
  • 24. 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 24 But set_value[T=bool] is outright wrong! template <class T> void set_value(DDS_DynamicData & d, int id, const std::vector<T> & v) { typename DynamicDataSeqTraits<T>::type seq; seq.loan_contiguous(&v[0], v.size(), v.capacity()); typename DynamicDataSeqTraits<T>::SetSeqFuncPtr fn = DynamicDataSeqTraits<T>::set_seq_func_ptr; d.*fn(id, seq); seq.unloan(); } std::vector<bool> layout incompatible • std::vector<bool> is often a space-efficient data structure • Each element occupies a single bit instead of a single byte • Does not follow many other std::vector invariants
  • 25. 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 25 Add std::vector<bool> overload of set_value template <class T> void set_value(DDS_DynamicData & d, int id, const std::vector<T> & v) { typename DynamicDataSeqTraits<T>::type seq; seq.loan_contiguous(&v[0], v.size(), v.size()); typename DynamicDataSeqTraits<T>::SetSeqFuncPtr fn = DynamicDataSeqTraits<T>::set_seq_func_ptr; d.*fn(id, seq); seq.unloan(); } void set_value(DDS_DynamicData & d, int id, const std::vector<bool> & v) { DDS_BooleanSeq seq; seq.ensure_length(v.size(), v.size()); std::copy(begin(v), end(v), &seq[0]); d.set_boolean_seq(id, seq); }
  • 26. Overload for Classic Enumerations • C++03 enumerations implicitly convert to an integer – User C++11’s type-safe enums if you don’t want that • The following overload works ... for now! • set_value(DDS_DynamicData &, int id, int32_t) 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 26 enums go here
  • 27. Overload for user-defined structs: “Foo” 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 27 template <class T> void set_value(DDS_DynamicData & d, int id, const T & t) { DDS_DynamicData inner; // Use boost.fusion to iterate over the public members of T // and use set_value recursively to populate the inner object. // Effectively equivalent to set_value(inner, 0, at<0>(t)); set_value(inner, 1, at<1>(t)); set_value(inner, 2, at<2>(t)); // and so on... d.set_complex(id, inner); }
  • 28. Enumerations are user-defined types too! • Addition of the template for Foo breaks enumerations • Solution: – Function Overloading Based on Arbitrary Properties of Types – Powered by SFINAE! • Substitution Failure Is Not An Error 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 28 template <class T> void set_value(DDS_DynamicData & d, int id, const T & t); All enums and user- defined structs resolve to this overload (that’s not what we want)
  • 29. A SFINAE Primer • Instantiating a function template is a two-phase process – Deduce template arguments – Substitute the deduced type in all occurrences of the template parameter • If the substitution process leads to an invalid type, argument deduction fails • The function is removed from the overload resolution set 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 29 int negate(int i) { return -i; } template <class F> typename F::result_type negate(const F& f) { return -f(); } negate(1);
  • 30. Function Enablers and Disablers • enable_if<true> keeps the template instantiation in the overload set • enable_if<false> removes the template instantiation from the overload set 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 30 template <bool B, class T = void> struct enable_if { typedef T type; }; template <class T> struct enable_if<false, T> {}; template <class T> typename enable_if<is_arithmetic<T>::value, T>::type foo(T t); template <class T> T bar (T t, typename enable_if<is_arithmetic<T>::value>::type* = 0);
  • 31. Using enable_if with type_traits • enable_if combined with type_traits is very powerful • Many type_traits are implemented using compiler intrinsics – Think of it as compile-time reflection in library form – E.g., is_union, is_pod, is_enum, any many many more – C++11 type_traits library is portable 10/2/2013 © 2012 RTI • COMPANY CONFIDENTIAL 31 template <class T> void set_value(DDS_DynamicData & d, int id, const T & t, typename enable_if<std::is_enum<T>::value>::type * = 0); template <class T> void set_value(DDS_DynamicData & d, int id, const T & t, typename enable_if<std::is_class<T>::value>::type * = 0);
  • 32. Recap set_value overloads so far 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 32 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &);[T=fundamental] 2 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 3 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<std::is_enum<T>::value>::type * = 0); 4 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<std::is_class<T>::value>::type * = 0); 5 • Works with – 18 fundamental types, std::vector of those, std::vector<bool>, scalar enumerations, and scalar user-defined structs. • No match for – std::vector<USER-DEFINED-STRUCTS>
  • 33. More overloads 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 33 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, disable_if<is_fundamental<T>::value>::type * = 0); 3 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 4 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 6 • Works with – std::vector<USER-DEFINED-STRUCT>, std::vector<bool>, scalar enumerations, scalar user-defined structs, 18 fundamental types, std::vector of those • Resolves incorrectly for std::vector<ENUMS> – Resolves to overload #3 but that’s wrong because enums are not fundamental types
  • 34. More overloads! 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 34 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, disable_if<is_fundamental<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 • std::vector<ENUMS> does not work due to ambiguity • Overload #3 and #4 are both viable for std::vector<ENUMS>
  • 35. More overloads! 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 35 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_class<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 • Support built-in arrays – Without array-specific overloads arrays map to the bool overload!
  • 36. 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 36 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_class<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0); 8 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0); 9 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0); 10 set_value Overloads for built-in arrays
  • 37. Overloads for std::vector<T[N]> ? 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 37 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_class<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0); 8 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0); 9 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0); 10 Works for vector of structs but not for vector of built-in arrays
  • 38. Overloads for std::vector<T[N]> 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 38 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, disable_if<is_fundamental<T>::value || is_enum<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0); 8 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0); 9 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0); 10 Works for vector of structs/built-in arrays/nested vectors
  • 39. The Overloads are Mutually Recursive 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 39 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, disable_if<is_fundamental<T>::value || is_enum<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0); 8 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0); 9 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0); 10 May call
  • 40. The Overloads are Mutually Recursive 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 40 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, disable_if<is_fundamental<T>::value || is_enum<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0); 8 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0); 9 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0); 10 Works for Multidimensional array or array of complex types
  • 41. Overloading for Other STL Containers! 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 41 Overloads # void set_value(DDS_DynamicData &, int, FundamentalTypes v); [18 overloads] 1 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 2 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_class<T>::value>::type * = 0); 3 template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> &, enable_if<is_enum<T>::value>::type * = 0); 4 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_class<T>::value>::type * = 0); 7 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_fundamental<typename remove_all_extents<T>::type>::value>::type * = 0); 8 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_enum<typename remove_all_extents<T>::type>::value>::type * = 0); 9 template <class T, unsigned N> void set_value(DDS_DynamicData &, int, const T(&arr)[N], typename enable_if<is_class<typename remove_all_extents<T>::type>::value>::type * = 0); 10 What about standard list, set, deque, unordered, etc.?
  • 42. Overloading for Other STL Containers! 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 42 template <class T> struct is_container : std::false_type {}; template <class T, class Alloc> struct is_container<std::vector<T, Alloc>> : std::true_type {}; template <class T, class Alloc> struct is_container<std::list<T, Alloc>> : std::true_type {}; template <class T, class Comp, class Alloc> struct is_container<std::set<T, Comp, Alloc>> : std::true_type {}; template <class Key, class Value, class Comp, class Alloc> struct is_container<std::map<Key, Value, Comp, Alloc>> : std::true_type {}; // and few more ...
  • 43. Overloading for Other STL Containers! 10/3/2013 © 2012 RTI • COMPANY CONFIDENTIAL 43 Overloads # template <class T> void set_value(DDS_DynamicData &, int, const std::vector<T> & enable_if<is_fundamental<T>::value>::type * = 0); 1 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename disable_if<!is_container<T>::value || std::is_fundamental<typename T::value_type>::value || std::is_enum<typename T::value_type>::value >::type * = 0) 2 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_container<T>::value && (is_fundamental<typename T::value_type>::value || std::is_enum<typename T::value_type>::value) && (is_vector<T>::value? is_bool_or_enum<typename T::value_type>::value : true)>::type * = 0); 3 void set_value(DDS_DynamicData &, int, const std::vector<bool> &); 4 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<!is_container<T>::value && is_class<T>::value>::type * = 0); 5 template <class T> void set_value(DDS_DynamicData &, int, const T &, typename enable_if<is_enum<T>::value>::type * = 0); 6 Overloads for fundamental scalar types and built-in arrays are not shown T is a std container of primitives but not vector <primitives except (bool & enums)> T is a std container of complex type Scalar complex type (Foo) Scalar Enums vector<fundamental>
  • 44. Using set_value overloads with Boost.Fusion struct SetValue { SetValue(DDS_DynamicData &dd); // ... template <typename T> void operator()(T& t) const { set_value(dd, ++id, t); } }; ShapeType shape(“BLUE”, x, y, 30); DDS_DynamicData dd(get_typecode<ShapeType>()); boost::fusion::for_each(shape, SetValue(dd)); 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 44 // shape.h struct ShapeType { std::string color; int x; int y; unsigned shapesize; }; // shape.h RTI_ADAPT_STRUCT( ShapeType, (std::string, color, KEY) (int, x) (int, y) (unsigned, shapesize))
  • 45. More Info • OMG DDS – http://portals.omg.org/dds/ • RTI Connext™ DDS – http://www.rti.com/products/dds/ • Example Code – https://cpptruths.googlecode.com/svn/trunk/cpp 0x/overloading-overdrive.cpp 10/4/2013 © 2012 RTI • COMPANY CONFIDENTIAL 45
  • 46. Thank you! © 2012 RTI • COMPANY CONFIDENTIAL