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  * - Scheduler functions are now in a new header `<mrpt/system/scheduler.h>`,
78  * not in the old `<mrpt/system/threads.h`:
79  * - `mrpt::system::changeCurrentProcessPriority()`
80  * - `mrpt::system::changeCurrentThreadPriority()`
81  * - `mrpt::utils::CObject::duplicate()` has been removed, use the equivalent
82  * (redundant) `mrpt::utils::CObject::clone()`.
83  * - CSerialPort, `mrpt::utils::net`, sockets: have been moved to its own new
84  * module \ref mrpt_comms_grp under namespace `mrpt::comms`.
85  * - Static variables have been dropped in favor of global getter/setter
86  * functions. This allowed removing all DLL import/export macros for Windows
87  * compilers. Important changes are:
88  * - `mrpt::math::randomGenerator` --> `mrpt::math::getRandomGenerator()`
89  * - `mrpt::global_settings` old static variables have been replaced by
90  * getter/setter functions.
91  * - `ASSERT_*` macros must now be ended with a semicolon, e.g. `ASSERT_(a>0);`
92  * - Serialization: See tutorial of the new module \ref mrpt_serialization_grp
93  * - To serialize an object to/from a CStream, you must now use CArchive:
94  * \code
95  * CStreamXXXX f; // Any mrpt::io::CStream type
96  * auto arch = mrpt::serialization::archiveFrom(f);
97  * arch << object;
98  * arch >> object;
99  * \endcode
100  * - The two methods `writeToStream()` and `readFromStream()` of old
101  * `CSerializable` classes must be replaced by the three methods:
102  * `serializeGetVersion()`, `serializeTo()`, and `serializeTo()`. See tutorials
103  * in \ref mrpt_serialization_grp.
104  * - Implicit constructor to convert from mrpt::poses::CPose3D to
105  * mrpt::math::TPose3D has been removed, due to the refactoring of mrpt::math
106  * and mrpt::poses into separate libraries. To convert CPose3D -> TPose3D, use
107  * the new method mrpt::poses::CPose3D::asTPose() \code mrpt::poses::CPose3D p1;
108  * mrpt::math::TPose3D p2 = p1; // ERROR in mrpt 2.0 (built in
109  * MRPT 1.*) mrpt::math::TPose3D p3 = p1.asTPose(); // OK for mrpt 2.0 \endcode
110  * - 16-bytes memory-aligned STL containers are now defined in separate
111  * headers, one for each container type, and based on templatized `using`.
112  * Example: \code
113  * // Old: MRPT 1.* code
114  * #include <mrpt/core/aligned_std_vector.h>
115  * mrpt::aligned_std_vector<Foo> v;
116  *
117  * // New: MRPT 2.* code
118  * #include <mrpt/core/aligned_std_vector.h>
119  * mrpt::aligned_std_vector<Foo> v;
120  * \endcode
121  * - mrpt::system::TTimeStamp is now a C++11-compatible std::chrono clock
122  * time_point. All existing backwards-compatible functions to handle dates and
123  * timestamps in MRPT remain, but C++11 chrono functions can be now also used
124  * instead. mrpt::system::secondsToTimestamp() has been removed since it mixed
125  * up a duration with time_point and may be prone to errors.
126  *
127  *
128  * **Optional changes**
129  * - Use the `Foo::ConstPtr` smart pointers when possible instead of its
130  * non-const counterpart.
131  *
132  *
133  */



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020