Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 20, 2009, 9:20:47 AM (15 years ago)
Author:
rgrieder
Message:

Merged pch branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/util/Convert.h

    r2710 r3196  
    4040#include <string>
    4141#include <sstream>
    42 #include <istream>
    43 #include <ostream>
    4442#include <typeinfo>
    4543
     
    123121namespace orxonox
    124122{
    125     namespace
     123    namespace detail
    126124    {
    127125        //! Little template that maps integers to entire types (Alexandrescu 2001)
     
    139137    struct ConverterFallback
    140138    {
    141         static bool convert(ToType* output, const FromType& input)
     139        FORCEINLINE static bool convert(ToType* output, const FromType& input)
    142140        {
    143141            COUT(2) << "Could not convert value of type " << typeid(FromType).name()
     
    151149    struct ConverterFallback<FromType*, ToType*>
    152150    {
    153         static bool convert(ToType** output, FromType* const input)
     151        FORCEINLINE static bool convert(ToType** output, FromType* const input)
    154152        {
    155153            ToType* temp = dynamic_cast<ToType*>(input);
     
    174172struct ConverterStringStream
    175173{
    176     static bool convert(ToType* output, const FromType& input)
     174    FORCEINLINE static bool convert(ToType* output, const FromType& input)
    177175    {
    178176        return orxonox::ConverterFallback<FromType, ToType>::convert(output, input);
     
    188186{
    189187    template <class FromType>
    190     inline bool operator <<(std::ostream& outstream,  const FromType& input)
     188    FORCEINLINE bool operator <<(std::ostream& outstream,  const FromType& input)
    191189    {
    192190        std::string temp;
     
    205203struct ConverterStringStream<FromType, std::string>
    206204{
    207     static bool convert(std::string* output, const FromType& input)
     205    FORCEINLINE static bool convert(std::string* output, const FromType& input)
    208206    {
    209207        using namespace fallbackTemplates;
     
    228226{
    229227    template <class ToType>
    230     inline bool operator >>(std::istream& instream, ToType& output)
     228    FORCEINLINE bool operator >>(std::istream& instream, ToType& output)
    231229    {
    232230        return orxonox::ConverterFallback<std::string, ToType>
     
    239237struct ConverterStringStream<std::string, ToType>
    240238{
    241     static bool convert(ToType* output, const std::string& input)
     239    FORCEINLINE static bool convert(ToType* output, const std::string& input)
    242240    {
    243241        using namespace fallbackTemplates;
     
    262260    // implicit cast not possible, try stringstream conversion next
    263261    template <class FromType, class ToType>
    264     inline bool convertImplicitely(ToType* output, const FromType& input, orxonox::Int2Type<false>)
     262    FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, detail::Int2Type<false>)
    265263    {
    266264        return ConverterStringStream<FromType, ToType>::convert(output, input);
     
    269267    // We can cast implicitely
    270268    template <class FromType, class ToType>
    271     inline bool convertImplicitely(ToType* output, const FromType& input, orxonox::Int2Type<true>)
     269    FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, detail::Int2Type<true>)
    272270    {
    273271        (*output) = static_cast<ToType>(input);
     
    284282    struct ConverterExplicit
    285283    {
    286         static bool convert(ToType* output, const FromType& input)
     284        FORCEINLINE static bool convert(ToType* output, const FromType& input)
    287285        {
    288286            // Try implict cast and probe first. If a simple cast is not possible, it will not compile
    289287            // We therefore have to out source it into another template function
    290288            const bool probe = ImplicitConversion<FromType, ToType>::exists;
    291             return convertImplicitely(output, input, orxonox::Int2Type<probe>());
     289            return convertImplicitely(output, input, detail::Int2Type<probe>());
    292290        }
    293291    };
     
    306304    */
    307305    template <class FromType, class ToType>
    308     inline bool convertValue(ToType* output, const FromType& input)
     306    FORCEINLINE bool convertValue(ToType* output, const FromType& input)
    309307    {
    310308        return ConverterExplicit<FromType, ToType>::convert(output, input);
    311     }
    312 
    313     // For compatibility reasons. The same, but with capital ConvertValue
    314     template<class FromType, class ToType>
    315     inline bool ConvertValue(ToType* output, const FromType& input)
    316     {
    317         return convertValue(output, input);
    318309    }
    319310
     
    331322    */
    332323    template<class FromType, class ToType>
    333     inline bool convertValue(ToType* output, const FromType& input, const ToType& fallback)
     324    FORCEINLINE bool convertValue(ToType* output, const FromType& input, const ToType& fallback)
    334325    {
    335326        if (convertValue(output, input))
     
    342333    }
    343334
    344     // for compatibility reason. (capital 'c' in ConvertValue)
    345     template<class FromType, class ToType>
    346     inline bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback)
    347     {
    348         return convertValue(output, input, fallback);
    349     }
    350 
    351335    // Directly returns the converted value, even if the conversion was not successful.
    352336    template<class FromType, class ToType>
    353     inline ToType getConvertedValue(const FromType& input)
     337    FORCEINLINE ToType getConvertedValue(const FromType& input)
    354338    {
    355339        ToType output;
     
    360344    // Directly returns the converted value, but uses the fallback on failure.
    361345    template<class FromType, class ToType>
    362     inline ToType getConvertedValue(const FromType& input, const ToType& fallback)
     346    FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback)
    363347    {
    364348        ToType output;
     
    370354    // That means you can call it exactly like static_cast<ToType>(fromTypeValue).
    371355    template<class ToType, class FromType>
    372     inline ToType omni_cast(const FromType& input)
     356    FORCEINLINE ToType multi_cast(const FromType& input)
    373357    {
    374358        ToType output;
     
    379363    // convert to string Shortcut
    380364    template <class FromType>
    381     inline std::string convertToString(FromType value)
    382     {
    383       return getConvertedValue<FromType, std::string>(value);
     365    FORCEINLINE std::string convertToString(FromType value)
     366    {
     367        return getConvertedValue<FromType, std::string>(value);
    384368    }
    385369
    386370    // convert from string Shortcut
    387371    template <class ToType>
    388     inline ToType convertFromString(std::string str)
    389     {
    390       return getConvertedValue<std::string, ToType>(str);
     372    FORCEINLINE ToType convertFromString(std::string str)
     373    {
     374        return getConvertedValue<std::string, ToType>(str);
    391375    }
    392376
     
    399383    struct ConverterExplicit<const char*, ToType>
    400384    {
    401         static bool convert(ToType* output, const char* input)
     385        FORCEINLINE static bool convert(ToType* output, const char* input)
    402386        {
    403387            return convertValue<std::string, ToType>(output, input);
     
    409393    struct ConverterExplicit<char, std::string>
    410394    {
    411         static bool convert(std::string* output, const char input)
     395        FORCEINLINE static bool convert(std::string* output, const char input)
    412396        {
    413397            *output = std::string(1, input);
     
    418402    struct ConverterExplicit<unsigned char, std::string>
    419403    {
    420         static bool convert(std::string* output, const unsigned char input)
     404        FORCEINLINE static bool convert(std::string* output, const unsigned char input)
    421405        {
    422406            *output = std::string(1, input);
     
    427411    struct ConverterExplicit<std::string, char>
    428412    {
    429         static bool convert(char* output, const std::string input)
     413        FORCEINLINE static bool convert(char* output, const std::string input)
    430414        {
    431415            if (input != "")
     
    439423    struct ConverterExplicit<std::string, unsigned char>
    440424    {
    441         static bool convert(unsigned char* output, const std::string input)
     425        FORCEINLINE static bool convert(unsigned char* output, const std::string input)
    442426        {
    443427            if (input != "")
     
    454438    struct ConverterExplicit<bool, std::string>
    455439    {
    456         static bool convert(std::string* output, const bool& input)
     440        FORCEINLINE static bool convert(std::string* output, const bool& input)
    457441        {
    458442            if (input)
Note: See TracChangeset for help on using the changeset viewer.