Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2017 for code/branches


Ignore:
Timestamp:
Oct 26, 2008, 12:46:44 PM (16 years ago)
Author:
rgrieder
Message:

Changed conversion_cast≠() to omni_cast≠() and added support for dynamic_cast.
Whenever you want to convert 2 pointers, it uses static_cast if the conversion is implicit (derived to base class) and dynamic_cast otherwise.
There is a drawback however: When static_cast is not possible and at least one of the two pointers is not from a polymorphic class, you get a compiler error that tells you exactly this. But who would want to convert an int* to OrxonoxClass* ?

Location:
code/branches/objecthierarchy
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/util/Convert.h

    r2016 r2017  
    139139                << " to type " << typeid(ToType).name() << std::endl;
    140140        return false;
     141    }
     142};
     143
     144// If all else fails, try a dynamic_cast for pointer types.
     145template <class FromType, class ToType>
     146struct ConverterFallback<FromType*, ToType*>
     147{
     148    static bool convert(ToType** output, FromType* const input)
     149    {
     150        ToType* temp = dynamic_cast<ToType*>(input);
     151        if (temp)
     152        {
     153            *output = temp;
     154            return true;
     155        }
     156        else
     157            return false;
    141158    }
    142159};
     
    345362// That means you can call it exactly like static_cast<ToType>(fromTypeValue).
    346363template<class ToType, class FromType>
    347 inline ToType conversion_cast(const FromType& input)
     364inline ToType omni_cast(const FromType& input)
    348365{
    349366    ToType output;
     
    354371// convert to string Shortcut
    355372template <class FromType>
    356 std::string convertToString(FromType value)
     373inline std::string convertToString(FromType value)
    357374{
    358375  return getConvertedValue<FromType, std::string>(value);
     
    361378// convert from string Shortcut
    362379template <class ToType>
    363 ToType convertFromString(std::string str)
     380inline ToType convertFromString(std::string str)
    364381{
    365382  return getConvertedValue<std::string, ToType>(str);
  • code/branches/objecthierarchy/visual_studio/vc8/directories.vsprops

    r1905 r2017  
    1313        <UserMacro
    1414                Name="LibDir"
    15                 Value="$(RootDir)\dependencies\$(SolutionName)\"
     15                Value="$(RootDir)..\lib_dist\vc8\dependencies\$(SolutionName)\"
    1616        />
    1717</VisualStudioPropertySheet>
Note: See TracChangeset for help on using the changeset viewer.