]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Utility.h
PolyLine updated.
[cpPlugins.git] / lib / cpExtensions / Utility.h
index ab42807a84dbeb567bd4aa2a363870e17808b4ce..b79f37985be42382e0d9ca36c156d2b06a29a152 100644 (file)
@@ -1,24 +1,25 @@
-#ifndef __CPEXTENSIONS__UTILITY__H__
-#define __CPEXTENSIONS__UTILITY__H__
+#ifndef __cpExtensions__Utility__h__
+#define __cpExtensions__Utility__h__
 
-#include <cpExtensions/Config.h>
 #include <chrono>
 #include <cstring>
 #include <fstream>
-#include <iostream>
 #include <string>
+#include <cpExtensions/Config.h>
 
 // -------------------------------------------------------------------------
-#ifdef cpExtensions_SYS_WINDOWS
-#  define cpExtensions_STRTOK( A, B, N ) strtok_s( A, B, N )
-#else // cpExtensions_SYS_WINDOWS
-#  define cpExtensions_STRTOK( A, B, N ) std::strtok( A, B )
-#endif // cpExtensions_SYS_WINDOWS
+#ifdef cpExtensions_OS_Windows
+#  define cpExtensions_STRTOK( A, B, N )  strtok_s( A, B, N )
+#  define cpExtensions_SPRINTF( B, S, O ) sprintf_s( B, S, "%s", O );
+#else // cpExtensions_OS_Windows
+#  define cpExtensions_STRTOK( A, B, N )  std::strtok( A, B )
+#  define cpExtensions_SPRINTF( B, S, O ) std::sprintf( B, "%s", O );
+#endif // cpExtensions_OS_Windows
 
 // -------------------------------------------------------------------------
-#define cpExtensions_CHRONO                                             \
-  std::chrono::duration_cast< std::chrono::milliseconds >(              \
-    std::chrono::system_clock::now( ).time_since_epoch( )               \
+#define cpExtensions_CHRONO                                     \
+  std::chrono::duration_cast< std::chrono::milliseconds >(      \
+    std::chrono::system_clock::now( ).time_since_epoch( )       \
     ).count( )
 
 // -------------------------------------------------------------------------
@@ -27,11 +28,11 @@ namespace cpExtensions
   // -----------------------------------------------------------------------
   inline bool IsPathSeparator( char c )
   {
-#ifdef cpExtensions_SYS_WINDOWS
-    return( c == '\\' || c == cpExtensions_PATH_SEPARATOR );
-#else // cpExtensions_SYS_WINDOWS
+#ifdef cpExtensions_OS_Windows
+    return( c == '/' || c == cpExtensions_PATH_SEPARATOR );
+#else // cpExtensions_OS_Windows
     return( c == cpExtensions_PATH_SEPARATOR );
-#endif // cpExtensions_SYS_WINDOWS
+#endif // cpExtensions_OS_Windows
   }
 
   // -----------------------------------------------------------------------
@@ -42,7 +43,7 @@ namespace cpExtensions
 
   // -----------------------------------------------------------------------
   template< class _TTokens >
-  inline void TokenizeString(
+  inline void Tokenize(
     _TTokens& tokens, const std::string& str, const std::string& delims
     )
   {
@@ -68,7 +69,7 @@ namespace cpExtensions
   }
 
   // -----------------------------------------------------------------------
-  inline std::string ReplaceString(
+  inline std::string Replace(
     const std::string& str, const std::string& sub, const std::string& nsub
     )
   {
@@ -80,9 +81,7 @@ namespace cpExtensions
   }
 
   // -----------------------------------------------------------------------
-  inline bool ReadFileIntoBuffer(
-    std::string& buffer, const std::string& fname
-    )
+  inline bool Read( std::string& buffer, const std::string& fname )
   {
     buffer = "";
     std::ifstream file_stream( fname.c_str( ) );
@@ -99,16 +98,26 @@ namespace cpExtensions
     return( true );
   }
 
+  // -----------------------------------------------------------------------
+  inline bool Write( const std::string& buffer, const std::string& fname )
+  {
+    std::ofstream file_stream( fname.c_str( ), std::ofstream::binary );
+    if( !file_stream )
+      return( false );
+    file_stream.write( buffer.c_str( ), buffer.size( ) );
+    return( true );
+  }
+
   // -----------------------------------------------------------------------
   inline std::string CanonicalPath( const std::string& path )
   {
     std::string ret = "";
-#ifdef cpExtensions_SYS_WINDOWS
+#ifdef cpExtensions_OS_Windows
     TCHAR  buffer[ 4096 ] = TEXT( "" );
     TCHAR** lppPart = { NULL };
     GetFullPathName( path.c_str( ), 4096, buffer, lppPart );
     ret = std::string( buffer );
-#else // cpExtensions_SYS_WINDOWS
+#else // cpExtensions_OS_Windows
     char* canonical_path = realpath( path.c_str( ), NULL );
     if( canonical_path != NULL )
     {
@@ -116,12 +125,12 @@ namespace cpExtensions
       free( canonical_path );
 
     } // fi
-#endif // cpExtensions_SYS_WINDOWS
+#endif // cpExtensions_OS_Windows
     return( ret );
   }
 
 } // ecapseman
 
-#endif // __CPEXTENSIONS__UTILITY__H__
+#endif // __cpExtensions__Utility__h__
 
 // eof - $RCSfile$