Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11098


Ignore:
Timestamp:
Jan 26, 2016, 8:32:16 PM (9 years ago)
Author:
muemart
Message:

Minor C++11 improvements:

  • Drop ImplicitConversion.h in favor of std::is_convertible.
  • Move constructor & assignment for MultiType and SubString. I'm not sure if the MultiType should convert types when moving. Currently it doesn't, because otherwise it would have no benefit over copying.
  • Use standard library functions for sleeping.
Location:
code/trunk/src/libraries/util
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/util/Convert.h

    r8858 r11098  
    128128#include <sstream>
    129129#include <typeinfo>
     130#include <type_traits>
    130131#include <loki/TypeManip.h>
    131132
    132133#include "Output.h"
    133 #include "ImplicitConversion.h"
    134134
    135135// disable warnings about possible loss of data
     
    308308    struct ConverterExplicit
    309309    {
    310         enum { probe = ImplicitConversion<FromType, ToType>::exists };
     310        static constexpr bool probe = std::is_convertible<FromType, ToType>::value;
    311311        ORX_FORCEINLINE static bool convert(ToType* output, const FromType& input)
    312312        {
  • code/trunk/src/libraries/util/MultiType.h

    r11071 r11098  
    100100#include <cassert>
    101101#include <string>
     102#include <utility>
    102103#include <OgreVector2.h>
    103104#include <OgreVector3.h>
     
    310311            /// Copyconstructor: Assigns value and type of the other MultiType.
    311312            inline MultiType(const MultiType& other) : value_(nullptr) { this->set(other); }
     313            /// Moveconstructor: Moves the value and its type from the other MultiType
     314            inline MultiType(MultiType&& other)      : value_(nullptr) { std::swap(this->value_, other.value_); };
    312315
    313316            /// Destructor: Deletes the MT_Value.
     
    320323            /// Assigns the value of the other MultiType and converts it to the current type of the MultiType.
    321324            inline                       MultiType& operator=(const MultiType& other) { this->set(other); return (*this); }
     325            /// Moves the value and the type of the other MultiType to this one.
     326            inline                       MultiType& operator=(MultiType&& other)      { std::swap(this->value_, other.value_); return (*this); }
    322327
    323328            /// Assigns the given value and converts it to the current type.
  • code/trunk/src/libraries/util/Sleep.cc

    r8858 r11098  
    3030@file
    3131@brief
    32     Implementation of three sleep functions. Avoids including windows.h
     32    Implementation of three sleep functions.
    3333*/
    3434
    3535#include "Sleep.h"
    36 #include "Output.h"
    3736
    38 #ifdef ORXONOX_PLATFORM_WINDOWS
    39 #ifndef WIN32_LEAN_AND_MEAN
    40 #  define WIN32_LEAN_AND_MEAN
    41 #endif
    42 #include <windows.h>
    43 #undef min
    44 #undef max
     37#include <chrono>
     38#include <thread>
    4539
    4640namespace orxonox
     
    4842    void usleep(unsigned long microseconds)
    4943    {
    50         //if (microseconds < 1000)
    51         //    orxout(internal_warning) << "Windows cannot sleep less than 1ms, ignoring" << endl;
    52         Sleep(microseconds / 1000);
     44        std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
    5345    }
    5446
    5547    void msleep(unsigned long milliseconds)
    5648    {
    57         Sleep(milliseconds);
     49        std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
    5850    }
    5951
    6052    void sleep(unsigned long seconds)
    6153    {
    62         Sleep(seconds * 1000);
     54        std::this_thread::sleep_for(std::chrono::seconds(seconds));
    6355    }
    6456}
    65 
    66 #else /* Linux/Apple */
    67 #include <unistd.h>
    68 
    69 namespace orxonox
    70 {
    71     void usleep(unsigned long usec)
    72     {
    73         ::usleep(usec);
    74     }
    75     void msleep(unsigned long msec)
    76     {
    77         ::usleep(msec * 1000);
    78     }
    79     void sleep(unsigned long sec)
    80     {
    81         ::usleep(sec * 1000000);
    82     }
    83 }
    84 
    85 #endif
  • code/trunk/src/libraries/util/SubString.h

    r11071 r11098  
    115115    public:
    116116        SubString();
     117        /// Copy constructor
     118        SubString(const SubString& other) = default;
     119        /// Move constructor
     120        SubString(SubString&& other) = default;
    117121        SubString(const std::string& line,
    118122                  const std::string& delimiters = SubString::WhiteSpaces,
     
    133137        // operate on the SubString
    134138        SubString& operator=(const SubString& other);
     139        /// Move assignment
     140        SubString& operator=(SubString&& other) = default;
    135141        bool operator==(const SubString& other) const;
    136142        bool compare(const SubString& other, size_t length = std::string::npos) const;
Note: See TracChangeset for help on using the changeset viewer.