Commit 1be608e9 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixing the code to work without C++11 (for nvcc 5.0).

parent 47e5629a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ if( CMAKE_BUILD_TYPE STREQUAL "Debug")
    set( EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/Debug/bin )
    set( debugExt -dbg )
    AddCompilerFlag( "-std=gnu++0x -DTEMPLATE_EXPLICIT_INSTANTIATION" )
    #AddCompilerFlag( "-DHAVE_NOT_CXX11 -DTEMPLATE_EXPLICIT_INSTANTIATION" )
else()
    set( PROJECT_BUILD_PATH ${PROJECT_SOURCE_DIR}/Release/src )
    set( PROJECT_TESTS_PATH ${PROJECT_SOURCE_DIR}/Release/tests )
@@ -26,6 +27,7 @@ else()
    #set( CXX_OPTIMIZE_FLAGS "-O3")
    OptimizeForArchitecture()
    AddCompilerFlag( "-std=gnu++0x -O3 -DNDEBUG -DTEMPLATE_EXPLICIT_INSTANTIATION" )
    #AddCompilerFlag( "-DHAVE_NOT_CXX11 -O3 -DNDEBUG -DTEMPLATE_EXPLICIT_INSTANTIATION" )
endif()

#####
+5 −0
Original line number Diff line number Diff line
@@ -90,8 +90,13 @@ class tnlArray : public tnlObject
    * Every time one touches this grid touches * size * sizeof( Real ) bytes are added
    * to transfered bytes in tnlStatistics.
    */
#ifdef HAVE_NOT_CXX11
   template< typename IndexType2 >
   void touch( IndexType2 touches = 1 ) const;
#else
   template< typename IndexType2 = Index >
   void touch( IndexType2 touches = 1 ) const;
#endif      

   //! Method for saving the object to a file as a binary data.
   bool save( tnlFile& file ) const;
+16 −15
Original line number Diff line number Diff line
@@ -104,34 +104,35 @@ class tnlFile
	}

	// TODO: this does not work for constant types
#ifdef HAVE_CXX11        
	template< typename Type, typename Device = tnlHost, typename Index = int >
#ifdef HAVE_NOT_CXX11
	template< typename Type, typename Device, typename Index >
	bool read( Type* buffer,
	           const Index& elements );

	template< typename Type, typename Device = tnlHost >
	template< typename Type, typename Device >
	bool read( Type* buffer );

	template< typename Type, typename Device = tnlHost, typename Index = int >
	template< typename Type, typename Device, typename Index >
	bool write( const Type* buffer,
	            const Index elements );

	template< typename Type, typename Device = tnlHost >
	template< typename Type, typename Device >
	bool write( Type* buffer );
#else        
	template< typename Type, typename Device, typename Index >
   template< typename Type, typename Device = tnlHost, typename Index = int >
   bool read( Type* buffer,
              const Index& elements );

	template< typename Type, typename Device >
   template< typename Type, typename Device = tnlHost >
   bool read( Type* buffer );

	template< typename Type, typename Device, typename Index >
   template< typename Type, typename Device = tnlHost, typename Index = int >
   bool write( const Type* buffer,
               const Index elements );

	template< typename Type, typename Device >
   template< typename Type, typename Device = tnlHost >
   bool write( Type* buffer );

#endif

	bool close();
+32 −13
Original line number Diff line number Diff line
@@ -301,31 +301,32 @@ template< class T > class tnlList
   //! Save the list in binary format
   bool Save( tnlFile& file ) const
   {
#ifdef HAVE_CXX11      
      file. write( &size );
#ifdef HAVE_NOT_CXX11
      file. write< const int, tnlHost >( &size );
      for( int i = 0; i < size; i ++ )
         if( ! file. write( &operator[]( i ), 1 ) )
         if( ! file. write< int, tnlHost, int >( &operator[]( i ), 1 ) )
            return false;
      return true;
#else
      file. write< const int, tnlHost >( &size );
      file. write( &size );
      for( int i = 0; i < size; i ++ )
         if( ! file. write< int, tnlHost, int >( &operator[]( i ), 1 ) )
         if( ! file. write( &operator[]( i ), 1 ) )
            return false;
      return true;

#endif            
   }

   //! Save the list in binary format using method save of type T
   bool DeepSave( tnlFile& file ) const
   {
#ifdef HAVE_CXX11      
      file. write( &size );
#ifdef HAVE_NOT_CXX11
      file. write< const int, tnlHost >( &size );
      for( int i = 0; i < size; i ++ )
         if( ! operator[]( i ). save( file ) ) return false;
      return true;
#else
      file. write< const int, tnlHost >( &size );
      file. write( &size );
      for( int i = 0; i < size; i ++ )
         if( ! operator[]( i ). save( file ) ) return false;
      return true;
@@ -335,10 +336,10 @@ template< class T > class tnlList
   //! Load the list
   bool Load( tnlFile& file )
   {
#ifdef HAVE_CXX11      
#ifdef HAVE_NOT_CXX11
      EraseAll();
      int _size;
      file. read( &_size, 1 );
      file. read< int, tnlHost >( &_size );
      if( _size < 0 )
      {
         cerr << "The curve size is negative." << endl;
@@ -347,7 +348,7 @@ template< class T > class tnlList
      T t;
      for( int i = 0; i < _size; i ++ )
      {
         if( ! file. read( &t, 1 ) )
         if( ! file. read< T, tnlHost >( &t ) )
            return false;
         Append( t );
      }
@@ -355,7 +356,7 @@ template< class T > class tnlList
#else
      EraseAll();
      int _size;
      file. read< int, tnlHost >( &_size );
      file. read( &_size, 1 );
      if( _size < 0 )
      {
         cerr << "The curve size is negative." << endl;
@@ -364,7 +365,7 @@ template< class T > class tnlList
      T t;
      for( int i = 0; i < _size; i ++ )
      {
         if( ! file. read< T, tnlHost >( &t ) )
         if( ! file. read( &t, 1 ) )
            return false;
         Append( t );
      }
@@ -375,6 +376,23 @@ template< class T > class tnlList
   //! Load the list using method Load of the type T
   bool DeepLoad( tnlFile& file )
   {
#ifdef HAVE_NOT_CXX11
      EraseAll();
      int _size;
      file. read< int, tnlHost >( &_size );
      if( _size < 0 )
      {
         cerr << "The list size is negative." << endl;
         return false;
      }
      for( int i = 0; i < _size; i ++ )
      {
         T t;
         if( ! t. load( file ) ) return false;
         Append( t );
      }
      return true;
#else
      EraseAll();
      int _size;
      file. read( &_size );
@@ -390,6 +408,7 @@ template< class T > class tnlList
         Append( t );
      }
      return true;
#endif            
   };
   
};
+5 −0
Original line number Diff line number Diff line
@@ -89,8 +89,13 @@ class tnlSharedArray : public tnlObject
    * Every time one touches this grid touches * size * sizeof( Real ) bytes are added
    * to transfered bytes in tnlStatistics.
    */
#ifdef HAVE_NOT_CXX11
   template< typename IndexType2 >
   void touch( IndexType2 touches = 1 ) const;
#else   
   template< typename IndexType2 = Index >
   void touch( IndexType2 touches = 1 ) const;
#endif   

   //! Method for saving the object to a file as a binary data.
   bool save( tnlFile& file ) const;
Loading