SILICON VALLEY. Sumant Tambe, Ph.D. Senior Software Research Engineer and Microsoft MVP Real-Time Innovations, Inc.

Similar documents
Short Notes of CS201

CS201 - Introduction to Programming Glossary By

Component Based DDS using C++11. R2DDS (Ruby to DDS) Johnny Willemsen CTO Remedy IT RTI London Connext Conference 2014

RTI Connext. Core Libraries and Utilities. Getting Started Guide Addendum for Extensible Types

RTI Connext DDS. Core Libraries and Utilities. Getting Started Guide Addendum for Extensible Types

Part X. Advanced C ++

Overload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018

RTI Connext DDS. Core Libraries Getting Started Guide Addendum for Extensible Types Version 5.2.0

Overload Resolution. Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019

use static size for this buffer

Advanced Systems Programming

RTI Connext DDS Core Libraries

Appendix B Boost.Python

An Introduction to Template Metaprogramming

Modern and Lucid C++ Advanced for Professional Programmers. Part 7 Compile-Time Computation. Department I - C Plus Plus

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Lecture 2 Polymorphism, Traits, Policies, and Inheritance

Using Enum Structs as Bitfields

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Introduction to Programming Using Java (98-388)

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

CCReflect has a few interesting features that are quite desirable for DigiPen game projects:

COMP322 - Introduction to C++

TDDD38 - Advanced programming in C++

CPSC 3740 Programming Languages University of Lethbridge. Data Types

Tokens, Expressions and Control Structures

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

Outline. 1 About the course

Introduce C# as Object Oriented programming language. Explain, tokens,

Object-Oriented Programming for Scientific Computing

Fundamentals of Programming Languages

CS

Technical Support. Phone: Trademarks

Proposed Resolution to TR1 Issues 3.12, 3.14, and 3.15

eprosima Dynamic Fast Buffers User Manual Version 0.2.0

CS 376b Computer Vision

Asynchronous Method Invocation through Connectors. IDL to C++11

Introduction to C++ Systems Programming

boost::enable_if Deep Down Boostimagical Fun Christian Bay and Kasper A Andersen Department of Computer Science University of Copenhagen

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

Introduction to C++ with content from

A Fast Review of C Essentials Part I

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

CS3157: Advanced Programming. Outline

C# and Java. C# and Java are both modern object-oriented languages

QUIZ. What is wrong with this code that uses default arguments?

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

STRICT_VARIANT. A simpler variant in C++ Chris Beck

Sample Copy. Not for Distribution.

Template metaprogramming techniques for concept-based specialization

C++11 and Compiler Update

Part XI. Algorithms and Templates. Philip Blakely (LSC) C++ Introduction 314 / 370

RAD Studio XE3 The Developer Force Multiplier

6.096 Introduction to C++ January (IAP) 2009

Making New Pseudo-Languages with C++

Basic Types & User Defined Types

19. Dynamic Data Structures II

CS Programming In C

Motivation was to facilitate development of systems software, especially OS development.

Stream Computing using Brook+

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

CE221 Programming in C++ Part 1 Introduction

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Expansion statements. Version history. Introduction. Basic usage

CORBA Programming with TAOX11. The C++11 CORBA Implementation

CS93SI Handout 04 Spring 2006 Apr Review Answers

G52CPP C++ Programming Lecture 18

Motivation was to facilitate development of systems software, especially OS development.

Part III. Advanced C ++

An introduction to C++ template programming

Programming. Principles and Practice Using C++ Bjarne Stroustrup. / Addison-Wesley. Second Edition

Review of the C Programming Language for Principles of Operating Systems

C The new standard

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Cpt S 122 Data Structures. Templates

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

C++1z: Concepts-Lite !!! !!! !!!! Advanced Developer Conference C slides:

C++14 Reflections Without Macros, Markup nor External Tooling

CoreDX DDS RPC over DDS

Absolute C++ Walter Savitch

Simulating Partial Specialization

OpenSplice LabVIEW Guide. Release 6.x

QUIZ. What are 3 differences between C and C++ const variables?

G52CPP C++ Programming Lecture 18. Dr Jason Atkin

GridKa School 2013: Effective Analysis C++ Templates

Review of the C Programming Language

Topic 6: A Quick Intro To C

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Instantiation of Template class

COEN244: Class & function templates

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Fast Introduction to Object Oriented Programming and C++

CS201 Some Important Definitions

C++ Objects Overloading Other C++ Peter Kristensen

Chapter 15 - C++ As A "Better C"

C++14 (Preview) Alisdair Meredith, Library Working Group Chair. Thursday, July 25, 13

Transcription:

SILICON VALLEY Sumant Tambe, Ph.D. Senior Software Research Engineer and Microsoft MVP Real-Time Innovations, Inc. www.rti.com

Data-Centric Communication Model in DDS 10/2/2013 2012 RTI 2

Data Distribution Service 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 10/2/2013 2012 RTI 3

Type Descriptions in DDS-XTypes (IDL, XSD, Java etc.) Data-Centric Typed All the Way! Code Generator Standard Mapping Java C/C++ 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 C# 10/2/2013 2013 RTI 4

DDS X-Types Standard Type System Type Representation Data Representation Language Binding 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

Example Type Representation IDL: Foo.idl struct Foo { string name; @key long ssn; @optional string phone; }; Language Binding IDL to C++ Language Mapping: struct Foo { std::string name; int ssn; std::string * phone; //... }; Data Representation IDL to CDR: 00000006 68656C6C 6F000000 00000002 6

Two Faces of DDS 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 10/2/2013 2013 RTI 7

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: // 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/2/2013 2012 RTI 9

Solution: A Pure C++11 Library-based Approach Example: // shape.h struct ShapeType { std::string color; int x; int y; unsigned shapesize; }; @Extensibility(EXTENSIBLE) struct ShapeType { @key string color; long x; long y; unsigned long shapesize; }; IDL Instead A substitute for lack of reflection in C++ // shape.h RTI_ADAPT_STRUCT( ShapeType, (std::string, color, KEY) (int, x) (int, y) (unsigned, shapesize)) 10/4/2013 2012 RTI 10

Read/Take Shapes (note C++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); 10/2/2013 2013 RTI 11

Slightly Complex Example 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 }; 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)) struct EventInfo { VetoTruth truth; int event_id; STATUS_FLAGS status; }; RTI_ADAPT_STRUCT( EventInfo, (VetoTruth, (int, (TATUS_FLAGS, truth) event_id, KEY) status)) 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 12

@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; Equivalent Type at Run-time Type representation is binary at runtime but shown here using the IDL syntax for readability 10/4/2013 2012 RTI COMPANY CONFIDENTIAL 13

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 Application GenericDataReader<T> GenericDataReaderListener<T> GenericDataWriter<T> Generic Functions (MakeTypecode, FillDD, ExtractDD, etc.) RTI_ADAPT Macros Type-driven access (overloading, template meta-programming, etc.) TypeCode, Dynamic Data API, DynamicDataTypeSupport Dynamic Data Type Plugin callbacks and CDR API DDS Core 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 17

class DDS_TypeCode {}; class DDS_DynamicData { public: explicit DDS_DynamicData(const DDS_TypeCode &) {} Extremely Simplified DynamicData API 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

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 19

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()); } 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 20

class DDS_DynamicData { public: Sequences (simplified DDS DynamicData API, again) 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 &) {} }; 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 21

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 22

set_value Template for std::vector of primitives 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(); Static method dispatch 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! 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 23

But set_value[t=bool] is outright wrong! 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()); std::vector<bool> layout incompatible } typename DynamicDataSeqTraits<T>::SetSeqFuncPtr fn = DynamicDataSeqTraits<T>::set_seq_func_ptr; d.*fn(id, seq); seq.unloan(); 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 24

Add std::vector<bool> overload of set_value 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); } 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 25

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) enums go here 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 26

Overload for user-defined structs: Foo 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); 10/4/2013 2012 RTI COMPANY CONFIDENTIAL 27

Enumerations are user-defined types too! Addition of the template for Foo breaks enumerations void set_value(dds_dynamicdata & d, int id, const T & t); All enums and userdefined structs resolve to this overload (that s not what we want) 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

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 int negate(int i) { return -i; } template <class F> typename F::result_type negate(const F& f) { return -f(); } negate(1); 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 29

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 template <bool B, class T = void> struct enable_if { typedef T type; }; struct enable_if<false, T> {}; typename enable_if<is_arithmetic<t>::value, T>::type foo(t t); T bar (T t, typename enable_if<is_arithmetic<t>::value>::type* = 0); 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 30

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 void set_value(dds_dynamicdata & d, int id, const T & t, typename enable_if<std::is_enum<t>::value>::type * = 0); void set_value(dds_dynamicdata & d, int id, const T & t, typename enable_if<std::is_class<t>::value>::type * = 0); 10/2/2013 2012 RTI COMPANY CONFIDENTIAL 31

Recap set_value overloads so far Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> &);[T=fundamental] 2 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 3 typename enable_if<std::is_enum<t>::value>::type * = 0); typename enable_if<std::is_class<t>::value>::type * = 0); 4 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> 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 32

More overloads Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, disable_if<is_fundamental<t>::value>::type * = 0); 2 3 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 4 typename enable_if<is_enum<t>::value>::type * = 0); typename enable_if<is_class<t>::value>::type * = 0); 5 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 10/4/2013 2012 RTI COMPANY CONFIDENTIAL 33

More overloads! Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, disable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); 2 3 4 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); typename enable_if<is_class<t>::value>::type * = 0); 6 7 std::vector<enums> does not work due to ambiguity Overload #3 and #4 are both viable for std::vector<enums> 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 34

More overloads! Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_class<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); 2 3 4 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); typename enable_if<is_class<t>::value>::type * = 0); 6 7 Support built-in arrays Without array-specific overloads arrays map to the bool overload! 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 35

set_value Overloads for built-in arrays Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_class<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); 2 3 4 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); typename enable_if<is_class<t>::value>::type * = 0); 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); 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); 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); 6 7 8 9 10 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 36

Overloads for std::vector<t[n]>? Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_class<t>::value>::type * = 0); 2 3 void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); Works for vector of structs but not for vector of built-in arrays 4 6 typename enable_if<is_class<t>::value>::type * = 0); 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); 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); 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); 7 8 9 10 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 37

Overloads for std::vector<t[n]> Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, disable_if<is_fundamental<t>::value is_enum<t>::value>::type * = 0); 2 3 void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); Works for vector of structs/built-in arrays/nested vectors 4 6 typename enable_if<is_class<t>::value>::type * = 0); 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); 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); 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); 7 8 9 10 10/4/2013 2012 RTI COMPANY CONFIDENTIAL 38

The Overloads are Mutually Recursive Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, disable_if<is_fundamental<t>::value is_enum<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); May call 2 3 4 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); typename enable_if<is_class<t>::value>::type * = 0); 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); 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); 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); 6 7 8 9 10 10/4/2013 2012 RTI COMPANY CONFIDENTIAL 39

The Overloads are Mutually Recursive Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, disable_if<is_fundamental<t>::value is_enum<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); 2 3 4 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); typename enable_if<is_class<t>::value>::type * = 0); Works for Multidimensional array or array of complex types 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); 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); 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); 6 7 8 9 10 10/4/2013 2012 RTI COMPANY CONFIDENTIAL 40

Overloading for Other STL Containers! Overloads # void set_value(dds_dynamicdata &, int, FundamentalTypes v); [18 overloads] 1 void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_class<t>::value>::type * = 0); void set_value(dds_dynamicdata &, int, const std::vector<t> &, enable_if<is_enum<t>::value>::type * = 0); What about standard list, set, deque, unordered, etc.? 2 3 4 void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 5 typename enable_if<is_enum<t>::value>::type * = 0); typename enable_if<is_class<t>::value>::type * = 0); 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); 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); 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); 6 7 8 9 10 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 41

Overloading for Other STL Containers! 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... 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 42

Overloading for Other STL Containers! void set_value(dds_dynamicdata &, int, const std::vector<t> & enable_if<is_fundamental<t>::value>::type * = 0); typename disable_if<!is_container<t>::value Overloads # std::is_fundamental<typename T::value_type>::value std::is_enum<typename T::value_type>::value >::type * = 0) 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); void set_value(dds_dynamicdata &, int, const std::vector<bool> &); 4 typename enable_if<!is_container<t>::value && is_class<t>::value>::type * = 0); typename enable_if<is_enum<t>::value>::type * = 0); vector<fundamental> T is a std container of complex type T is a std container of primitives but not vector <primitives except (bool & enums)> Scalar complex type (Foo) Scalar Enums 1 2 3 5 6 Overloads for fundamental scalar types and built-in arrays are not shown 10/3/2013 2012 RTI COMPANY CONFIDENTIAL 43

Using set_value overloads with Boost.Fusion // shape.h struct ShapeType { std::string color; int x; int y; unsigned shapesize; }; 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)); // shape.h RTI_ADAPT_STRUCT( ShapeType, (std::string, color, KEY) (int, x) (int, y) (unsigned, shapesize)) 10/4/2013 2012 RTI COMPANY CONFIDENTIAL 44

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