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-2017, 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 /** \page porting_mrpt2 Porting code from MRPT 1.{3,4,5} to MRPT 2.*
11 *
12 * MRPT 2.0 includes several fundamental changes, most of them related to API clean ups
13 * and the introduction of C++14 as the minimum supported version of the language.
14 *
15 * Existing user applications may need to be adapted to continue compiling and working
16 * as usual after updating to MRPT 2.*:
17 *
18 * **Mandatory changes**
19 * - Your project must use C++14. Using CMake this is easy by adding this right after your top-level `PROJECT`:
20 * \code
21 * CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
22 * set (CMAKE_CXX_STANDARD 14) # Require C++14
23 * \endcode
24 * - **Smart pointers** are now standard [`std::shared_ptr<>`](http://en.cppreference.com/w/cpp/memory/shared_ptr) instead of those based on `stlplus`. Required changes:
25 * - `ptr.clear()` --> `ptr.reset()`. Also, notice that the former `stlplus` semantics of `clear()` deleting **all** copies of the object, as hold by different smart pointers, is no longer maintained. There is no longer such a possibility, since the C++11 standard does not allow it to happen (and it makes sense in this way).
26 * - `ptr.clear_unique()` --> `ptr.reset()`. (Read this note above)
27 * - `ptr.make_unique()` does no longer exists, and does not make sense (read above).
28 * - `ptr.pointer()` --> `ptr.get()`
29 * - Smart pointers have been renamed from `CFooPtr` to the more standard `CFoo::Ptr`, with a new pointer-to-const version `CFoo::ConstPtr`.
30 * - Note: To help with porting and maintaining existing code bases, MRPT >=1.5.4 offers MRPT2-like `CFoo::Ptr` smart pointers. Refer to changelog of mrpt 1.5.4.
31 * - You can keep using code like:
32 * \code
33 * CFoo::Ptr o = CFoo::Create();
34 * \endcode
35 * in MRPT 2.0 to create a smart pointer, but can also use `std::make_shared<CFoo>()`, or `mrpt::make_aligned_shared<CFoo>()` if the class must be memory-aligned (typically, if it contains Eigen matrices).
36 * The arguments of `Create()` are now [perfectly-forwarded](http://en.cppreference.com/w/cpp/utility/forward) to the class ctor, so the parameter list must exactly match any of the available ctors.
37 * - Smart pointer typecasting now is done via C++11 standard functions:
38 * - Example: Old code
39 * \code
40 * CObservationPtr obs = getObsFromSomewhere();
41 * CObservationGPSPtr gps = CObservationGPS(obs);
42 * \endcode
43 * becomes pure C++14 in MRPT 2.0:
44 * \code
45 * CObservation::Ptr obs = getObsFromSomewhere();
46 * CObservationGPS::Ptr gps = std::dynamic_pointer_cast<CObservationGPS>(obs);
47 * \endcode
48 * or, if you need to keep your code compatible with MRPT >=1.5.4:
49 * \code
50 * CObservation::Ptr obs = getObsFromSomewhere();
51 * CObservationGPS::Ptr gps = mrpt::ptr_cast<CObservationGPS>::from(obs);
52 * \endcode
53 * - Threads, semaphores and mutexes are now based on C++11 standard library. Required changes:
54 * - `mrpt::synch::CCriticalSection cs;` --> `std::mutex cs;`
55 * - `mrpt::synch::CCriticalSectionLocker lock(&cs);` --> `std::lock_guard<std::mutex> lock(cs);`
56 * - `mrpt::system::TThreadHandle h = mrpt::system::createThread(...);` --> `std::thread h = std::thread(...);`
57 * - `mrpt::system::sleep(5);` --> `std::this_thread::sleep_for(5ms);`
58 * - `mrpt::synch::CSemaphore sem; sem.waitForSignal(timeout); sem.release();` --> `std::promise<void> sem; auto fut = sem.get_future(); fut.wait_for(...); sem.set_value();`
59 * - `mrpt::utils::CObject::duplicate()` has been removed, use the equivalent (redundant) `mrpt::utils::CObject::clone()`.
60 * - CSerialPort, `mrpt::utils::net`, sockets: have been moved to its own new module \ref mrpt_comms_grp under namespace `mrpt::comms`.
61 * - Static variables have been dropped in favor of global getter/setter functions. This allowed removing all DLL import/export macros for Windows compilers. Important changes are:
62 * - `mrpt::math::randomGenerator` --> `mrpt::math::getRandomGenerator()`
63 * - `mrpt::global_settings` old static variables have been replaced by getter/setter functions.
64 *
65 * **Optional changes**
66 * - Use the `Foo::ConstPtr` smart pointers when possible instead of its non-const counterpart.
67 *
68 *
69 */



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019