Commit 04d0568a authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Added parseObjectType function example.

parent e55f31a9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ ADD_CUSTOM_COMMAND( COMMAND ObjectExample_getType > ObjectExample_getType.out OU

ADD_EXECUTABLE( ParameterContainerExample ParameterContainerExample.cpp )

ADD_EXECUTABLE( ParseObjectTypeExample ParseObjectTypeExample.cpp )
ADD_CUSTOM_COMMAND( COMMAND ParseObjectTypeExample > ParseObjectTypeExample.out OUTPUT ParseObjectTypeExample.out )

ADD_EXECUTABLE( StringExample StringExample.cpp )
ADD_CUSTOM_COMMAND( COMMAND StringExample > StringExample.out OUTPUT StringExample.out )

@@ -59,6 +62,7 @@ ADD_EXECUTABLE( VectorExample VectorExample.cpp )

ADD_CUSTOM_TARGET( run ALL DEPENDS
   ObjectExample_getType.out
   ParseObjectTypeExample.out
   StringExample.out
   StringExampleGetAllocatedSize.out
   StringExampleReplace.out
+16 −0
Original line number Diff line number Diff line
#include <iostream>
#include <TNL/Object.h>
#include <unistd.h>

using namespace TNL;
using namespace std;

int main()
{
   auto parsedObjectType = parseObjectType( String( "MyObject< Value, Device, Index >" ) );
   for( auto &token : parsedObjectType )
   {
      cout << token << endl;
   }
}
+18 −6
Original line number Diff line number Diff line
@@ -30,6 +30,13 @@ namespace TNL {
 * 
 * Since the virtual destructor is not defined as \ref __cuda_callable__, 
 * objects inherited from Object should not be created in CUDA kernels.
 * 
 * In addition to methods of this class, see the following related functions:
 * 
 * \ref getObjectType
 * 
 * \ref parseObjectType
 * 
 */
class Object
{
@@ -141,19 +148,24 @@ class Object
String getObjectType( File& file );

/**
 * \brief Does the same as \ref getObjectType but with \e fileName parameter instead of file.
 * \brief Does the same as \ref getObjectType but with a \e fileName parameter instead of file.
 * 
 * @param fileName name of file where the object is stored
 * @param type string with the object type
 * @param fileName name of a file where the object is stored
 * @return string with the object type
 */
String getObjectType( const String& fileName );

/**
 * \brief Parses the object type
 * 
 * @param objectType is a string with the object type
 * @return list of strings where the first one is the object type and the next
 * strings are the template parameters
 * @param objectType is a string with the object type to be parsed.
 * @return vector of strings where the first one is the object type and the next
 * strings are the template parameters.
 *
 * \par Example
 * \include ParseObjectTypeExample.cpp
 * \par Output
 * \include ParseObjectTypeExample.out
 */
std::vector< String >
parseObjectType( const String& objectType );