ossimlabs / ossim

Core OSSIM (Open Source Software Image Map) package including C++ code for OSSIM library, command-line applications, tests, and build system
MIT License
295 stars 142 forks source link

Errors when building 2.12.0 on Visual Studio 2017 #257

Open madebr opened 4 years ago

madebr commented 4 years ago

Hello,

I'm trying to package ossim 2.12.0 for conan at https://github.com/conan-io/conan-center-index/pull/2459

Using Visual Studio, building a static ossim fails with the following error:

Severity    Code    Description Project File    Line    Suppression State
Error   C2666   'ossimString::operator !=': 2 overloads have similar conversions    ossim   C:\Users\maarten\.conan\data\ossim\2.12.0\_\_\build\5bdfed110172ecef3a963112a861792e242d368e\source_subfolder\src\base\ossimFilename.cpp    1132    
Error   C2666   'ossimString::operator ==': 4 overloads have similar conversions    ossim   C:\Users\maarten\.conan\data\ossim\2.12.0\_\_\build\5bdfed110172ecef3a963112a861792e242d368e\source_subfolder\src\support_data\ossimNitfRsmecbTag.cpp   266 

The 4 operator== overloads about which the compiler complains are:

   friend OSSIM_DLL bool operator==(const char* lhs, const ossimString& rhs);
   friend OSSIM_DLL bool operator==(const std::string& lhs, const ossimString& rhs);
   bool operator==(const ossimString& rhs) const;
   bool operator==(const char* rhs) const;

The 2 operator!= overloads about which the compiler complains are:

   bool operator!=(const ossimString& rhs) const;
   bool operator!=(const char* rhs) const;
madebr commented 3 years ago

This patch fixed my problem:

--- include/ossim/base/ossimString.h
+++ include/ossim/base/ossimString.h
@@ -235,7 +235,7 @@ public:
    }

    /**
-    *  @brief  Test if this ossimString is equal to a C sting.
+    *  @brief  Test if this ossimString is equal to a C string.
     *  @param rhs C string to compare.
     *  @return  True if strings are equal.
     *  False if rhs is not equal null or null.
@@ -250,6 +250,22 @@ public:
       return result;
    }

+   /**
+    *  @brief  Test if this ossimString is equal to character.
+    *  @param rhs character to compare.
+    *  @return  True if strings are equal.
+    *  False if rhs is not equal null or null.
+    */
+   bool operator==(char rhs) const
+   {
+      bool result = false;
+      if (rhs)
+      {
+         result = (m_str.compare(std::string(1, rhs)) == 0);
+      }
+      return result;
+   }
+
    /**
     *  @brief  Test if this ossimString is not equal to another ossimString.
     *  @param rhs ossimString to compare.
@@ -261,7 +277,7 @@ public:
    }

    /**
-    *  @brief  Test if this ossimString is not equal to a C sting.
+    *  @brief  Test if this ossimString is not equal to a C string.
     *  @param rhs C string to compare.
     *  @return  True if strings are not equal or rhs is null.
     *  False if rhs equal to this string.
@@ -276,6 +292,16 @@ public:
       return result;
    }

+   /**
+    *  @brief  Test if this ossimString is not equal to a char.
+    *  @param ch character to compare.
+    *  @return  True if char is not equal.  False otherwise.
+    */
+   bool operator!=(char rhs) const
+   {
+       return !(m_str.compare(std::string(1, rhs)) == 0);
+   }
+
    bool operator<(const ossimString& rhs) const
    {
       return m_str < rhs.m_str;