BugInTheSYS

Untitled

Oct 4th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. // main.cpp
  2.  
  3. // Function and variable declarations and/or definitions, Preprocessor directives, etc...
  4. // among those the following lines, intended to be normal function declarations:
  5.  
  6. template < class T > std::string GetMemory< T >( void *base );
  7. template < class T > void SetMemory< T >( std::string &value, void *base );
  8.  
  9. // CODE
  10. // And now, as normally, their definitions:
  11.  
  12. template < class T >
  13. std::string GetMemory< T >( void *base ) {
  14.   std::string result;
  15.   unsigned int i,
  16.                length = sizeof( T ),
  17.                beginning = ( unsigned int )( char* )base,
  18.                end = beginning + length;
  19.   for( i = beginning; i <= end; i++ ) {
  20.     result += *( ( char* )i );
  21.   }
  22.   return result;
  23. }
  24.  
  25. template < class T >
  26. void SetMemory< T >( std::string &value, void *base ) {
  27.   unsigned int i,
  28.                length = sizeof( T ),
  29.                beginning = ( unsigned int )( char* )base,
  30.                end = beginning + length;
  31.   for( i = beginning; i <= end; i++ ) {
  32.     *( ( char* )i ) = value[ start + i - beginning ];
  33.   }
  34.   value = value->substr( length, value->npos );
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment