Main MRPT website > C++ reference for MRPT 1.9.9
porting_mrpt2.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+
9  */
10 
11 /** \page porting_mrpt2 Porting code from MRPT 1.{3,4,5} to MRPT 2.*
12  *
13  * MRPT 2.0 includes several fundamental changes, most of them related to API
14  * clean ups and the introduction of C++14 as the minimum supported version of
15  * the language.
16  *
17  * Existing user applications may need to be adapted to continue compiling and
18  * working as usual after updating to MRPT 2.*:
19  *
20  * **Mandatory changes**
21  * - Your project must use C++17. Using CMake this is easy by adding this right
22  * after your top-level `PROJECT`: \code CMAKE_MINIMUM_REQUIRED(VERSION 3.1) set
23  * (CMAKE_CXX_STANDARD 17) # Require C++17 \endcode
24  * - **Smart pointers** are now standard
25  * [`std::shared_ptr<>`](http://en.cppreference.com/w/cpp/memory/shared_ptr)
26  * instead of those based on `stlplus`. Required changes:
27  * - `ptr.clear()` --> `ptr.reset()`. Also, notice that the former
28  * `stlplus` semantics of `clear()` deleting **all** copies of the object, as
29  * hold by different smart pointers, is no longer maintained. There is no longer
30  * such a possibility, since the C++11 standard does not allow it to happen (and
31  * it makes sense in this way).
32  * - `ptr.clear_unique()` --> `ptr.reset()`. (Read this note above)
33  * - `ptr.make_unique()` does no longer exists, and does not make sense
34  * (read above).
35  * - `ptr.pointer()` --> `ptr.get()`
36  * - Smart pointers have been renamed from `CFooPtr` to the more standard
37  * `CFoo::Ptr`, with a new pointer-to-const version `CFoo::ConstPtr`.
38  * - Note: To help with porting and maintaining existing code bases, MRPT
39  * >=1.5.4 offers MRPT2-like `CFoo::Ptr` smart pointers. Refer to changelog of
40  * mrpt 1.5.4.
41  * - You can keep using code like:
42  * \code
43  * CFoo::Ptr o = CFoo::Create();
44  * \endcode
45  * in MRPT 2.0 to create a smart pointer, but can also use
46  * `std::make_shared<CFoo>()`, or `mrpt::make_aligned_shared<CFoo>()` if the
47  * class must be memory-aligned (typically, if it contains Eigen matrices). The
48  * arguments of `Create()` are now
49  * [perfectly-forwarded](http://en.cppreference.com/w/cpp/utility/forward) to
50  * the class ctor, so the parameter list must exactly match any of the available
51  * ctors.
52  * - Smart pointer typecasting now is done via C++11 standard functions:
53  * - Example: Old code
54  * \code
55  * CObservationPtr obs = getObsFromSomewhere();
56  * CObservationGPSPtr gps = CObservationGPS(obs);
57  * \endcode
58  * becomes pure C++14 in MRPT 2.0:
59  * \code
60  * CObservation::Ptr obs = getObsFromSomewhere();
61  * CObservationGPS::Ptr gps =
62  * std::dynamic_pointer_cast<CObservationGPS>(obs); \endcode or, if you need to
63  * keep your code compatible with MRPT >=1.5.4: \code CObservation::Ptr obs =
64  * getObsFromSomewhere(); CObservationGPS::Ptr gps =
65  * mrpt::ptr_cast<CObservationGPS>::from(obs); \endcode
66  * - Threads, semaphores and mutexes are now based on C++11 standard library.
67  * Required changes:
68  * - `mrpt::synch::CCriticalSection cs;` --> `std::mutex cs;`
69  * - `mrpt::synch::CCriticalSectionLocker lock(&cs);` -->
70  * `std::lock_guard<std::mutex> lock(cs);`
71  * - `mrpt::system::TThreadHandle h = mrpt::system::createThread(...);` -->
72  * `std::thread h = std::thread(...);`
73  * - `mrpt::system::sleep(5);` --> `std::this_thread::sleep_for(5ms);`
74  * - `mrpt::synch::CSemaphore sem; sem.waitForSignal(timeout);
75  * sem.release();` --> `std::promise<void> sem; auto fut = sem.get_future();
76  * fut.wait_for(...); sem.set_value();`
77  * - `mrpt::utils::CObject::duplicate()` has been removed, use the equivalent
78  * (redundant) `mrpt::utils::CObject::clone()`.
79  * - CSerialPort, `mrpt::utils::net`, sockets: have been moved to its own new
80  * module \ref mrpt_comms_grp under namespace `mrpt::comms`.
81  * - Static variables have been dropped in favor of global getter/setter
82  * functions. This allowed removing all DLL import/export macros for Windows
83  * compilers. Important changes are:
84  * - `mrpt::math::randomGenerator` --> `mrpt::math::getRandomGenerator()`
85  * - `mrpt::global_settings` old static variables have been replaced by
86  * getter/setter functions.
87  * - `ASSERT_*` macros must now be ended with a semicolon, e.g. `ASSERT_(a>0);`
88  * - Serialization: See tutorial of the new module \ref mrpt_serialization_grp
89  * - To serialize an object to/from a CStream, you must now use CArchive:
90  * \code
91  * CStreamXXXX f; // Any mrpt::io::CStream type
92  * auto arch = mrpt::serialization::archiveFrom(f);
93  * arch << object;
94  * arch >> object;
95  * \endcode
96  * - The two methods `writeToStream()` and `readFromStream()` of old
97  * `CSerializable` classes must be replaced by the three methods:
98  * `serializeGetVersion()`, `serializeTo()`, and `serializeTo()`. See tutorials
99  * in \ref mrpt_serialization_grp.
100  * - Implicit constructor to convert from mrpt::poses::CPose3D to
101  * mrpt::math::TPose3D has been removed, due to the refactoring of mrpt::math
102  * and mrpt::poses into separate libraries. To convert CPose3D -> TPose3D, use
103  * the new method mrpt::poses::CPose3D::asTPose() \code mrpt::poses::CPose3D p1;
104  * mrpt::math::TPose3D p2 = p1; // ERROR in mrpt 2.0 (built in
105  * MRPT 1.*) mrpt::math::TPose3D p3 = p1.asTPose(); // OK for mrpt 2.0 \endcode
106  * - 16-bytes memory-aligned STL containers are now defined in separate
107  * headers, one for each container type, and based on templatized `using`.
108  * Example: \code
109  * // Old: MRPT 1.* code
110  * #include <mrpt/core/aligned_std_vector.h>
111  * mrpt::aligned_std_vector<Foo> v;
112  *
113  * // New: MRPT 2.* code
114  * #include <mrpt/core/aligned_std_vector.h>
115  * mrpt::aligned_std_vector<Foo> v;
116  * \endcode
117  *
118  *
119  *
120  * **Optional changes**
121  * - Use the `Foo::ConstPtr` smart pointers when possible instead of its
122  * non-const counterpart.
123  *
124  *
125  */



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST