Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 827


Ignore:
Timestamp:
Feb 18, 2008, 12:54:30 AM (16 years ago)
Author:
landauf
Message:

some template-specializations in Convert.h

File:
1 edited

Legend:

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

    r792 r827  
    3737
    3838#include "UtilPrereqs.h"
     39#include "Math.h"
    3940
    4041// DEFAULT CLASS
     
    4243class _UtilExport Converter
    4344{
    44  public:
    45   bool operator()(ToType* output, const FromType& input) const
    46   {
    47     return false;
    48   }
     45  public:
     46    bool operator()(ToType* output, const FromType& input) const
     47    {
     48      return false;
     49    }
    4950};
    5051
     
    5354class _UtilExport Converter<FromType, std::string>
    5455{
    55  public:
    56   bool operator()(std::string* output, const FromType& input) const
    57   {
    58     std::ostringstream oss;
    59     if (oss << input)
     56  public:
     57    bool operator()(std::string* output, const FromType& input) const
    6058    {
    61       (*output) = oss.str();
    62       return true;
     59      std::ostringstream oss;
     60      if (oss << input)
     61      {
     62        (*output) = oss.str();
     63        return true;
     64      }
     65      else
     66        return false;
    6367    }
    64     else
    65       return false;
    66   }
    6768};
    6869
     
    7172class _UtilExport Converter<std::string, ToType>
    7273{
    73  public:
    74   bool operator()(ToType* output, const std::string& input) const
    75   {
    76     std::istringstream iss(input);
    77     if (iss >> (*output))
    78       return true;
    79     else
    80       return false;
    81   }
     74  public:
     75    bool operator()(ToType* output, const std::string& input) const
     76    {
     77      std::istringstream iss(input);
     78      if (iss >> (*output))
     79        return true;
     80      else
     81        return false;
     82    }
    8283};
    8384
     
    102103}
    103104
     105
     106
     107// MORE SPECIALISATIONS
     108// Vector2 to std::string
     109template <>
     110class _UtilExport Converter<orxonox::Vector2, std::string>
     111{
     112  public:
     113    bool operator()(std::string* output, const orxonox::Vector2& input) const
     114    {
     115      std::ostringstream ostream;
     116      if (ostream << input.x << "," << input.y)
     117      {
     118        (*output) = ostream.str();
     119        return true;
     120      }
     121
     122      return false;
     123    }
     124};
     125
     126// Vector3 to std::string
     127template <>
     128class _UtilExport Converter<orxonox::Vector3, std::string>
     129{
     130  public:
     131    bool operator()(std::string* output, const orxonox::Vector3& input) const
     132    {
     133      std::ostringstream ostream;
     134      if (ostream << input.x << "," << input.y << "," << input.z)
     135      {
     136        (*output) = ostream.str();
     137        return true;
     138      }
     139
     140      return false;
     141    }
     142};
     143
     144// Vector4 to std::string
     145template <>
     146class _UtilExport Converter<orxonox::Vector4, std::string>
     147{
     148  public:
     149    bool operator()(std::string* output, const orxonox::Vector4& input) const
     150    {
     151      std::ostringstream ostream;
     152      if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
     153      {
     154        (*output) = ostream.str();
     155        return true;
     156      }
     157
     158      return false;
     159    }
     160};
     161
     162// Quaternion to std::string
     163template <>
     164class _UtilExport Converter<orxonox::Quaternion, std::string>
     165{
     166  public:
     167    bool operator()(std::string* output, const orxonox::Quaternion& input) const
     168    {
     169      std::ostringstream ostream;
     170      if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
     171      {
     172        (*output) = ostream.str();
     173        return true;
     174      }
     175
     176      return false;
     177    }
     178};
     179
     180// ColourValue to std::string
     181template <>
     182class _UtilExport Converter<orxonox::ColourValue, std::string>
     183{
     184  public:
     185    bool operator()(std::string* output, const orxonox::ColourValue& input) const
     186    {
     187      std::ostringstream ostream;
     188      if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
     189      {
     190        (*output) = ostream.str();
     191        return true;
     192      }
     193
     194      return false;
     195    }
     196};
     197
    104198#endif /* _Convert_H__ */
Note: See TracChangeset for help on using the changeset viewer.