test_icl_core_convert.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 #include <icl_core/Convert.h>
25 
26 #include <iostream>
27 
28 struct Foo
29 {
30  Foo() : foo(42) { }
31  int foo;
32 };
33 
34 struct Bar
35 {
36  Bar() : bar(23) { }
37  int bar;
38 };
39 
40 std::ostream& operator << (std::ostream& os, const Foo& foo)
41 {
42  return os << "Foo:" << foo.foo;
43 }
44 
45 std::ostream& operator << (std::ostream& os, const Bar& bar)
46 {
47  return os << "Bar:" << bar.bar;
48 }
49 
50 namespace icl_core {
51 
52 template <>
53 void convert<>(const Foo& from, Bar& to)
54 {
55  to.bar = from.foo;
56 }
57 
58 template <>
59 void convert<>(const Bar& from, Foo& to)
60 {
61  to.foo = from.bar;
62 }
63 
64 }
65 
66 int main()
67 {
68  Foo foo;
69  Bar bar;
70 
71  Bar bar2 = icl_core::convert<Bar>(foo);
72  Foo foo2 = icl_core::convert<Foo>(bar);
73 
74  std::cout << "Original objects: " << foo << " " << bar << "\n"
75  << "Converted objects: " << foo2 << " " << bar2 << std::endl;
76  return 0;
77 }
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
std::ostream & operator<<(std::ostream &os, const Foo &foo)
int main()


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58