ObjectExample_getType.cpp 1.56 KB
Newer Older
1
#include <iostream>
2
#include <TNL/TypeInfo.h>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <TNL/Object.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>

using namespace TNL;
using namespace std;

template< typename Value,
          typename Device >
class MyArray : public Object
{
   public:

      static String getSerializationType()
      {
18
         return "MyArray< " + TNL::getType< Value >() + ", " + getType< Devices::Host >() + " >";
19 20
      }

21
      virtual String getSerializationTypeVirtual() const override
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
      {
         return getSerializationType();
      }
};

int main()
{
   using HostArray = MyArray< int, Devices::Host >;
   using CudaArray = MyArray< int, Devices::Cuda >;

   HostArray hostArray;
   CudaArray cudaArray;
   Object* hostArrayPtr = &hostArray;
   Object* cudaArrayPtr = &cudaArray;

   // Object types
38 39
   cout << "HostArray type is                  " << getType< HostArray >() << endl;
   cout << "hostArrayPtr type is               " << getType( *hostArrayPtr ) << endl;
40

41 42
   cout << "CudaArray type is                  " << getType< CudaArray >() << endl;
   cout << "cudaArrayPtr type is               " << getType( *cudaArrayPtr ) << endl;
43 44 45 46 47 48 49 50

   // Object serialization types
   cout << "HostArray serialization type is    " << HostArray::getSerializationType() << endl;
   cout << "hostArrayPtr serialization type is " << hostArrayPtr->getSerializationTypeVirtual() << endl;

   cout << "CudaArray serialization type is    " << CudaArray::getSerializationType() << endl;
   cout << "cudaArrayPtr serialization type is " << cudaArrayPtr->getSerializationTypeVirtual() << endl;
}