Just some C++ snippets I've had stowed away..... *wave*
Vector example
Code:#include <iostream> #include <vector> using namespace std; int main() { int Val; typedef vector<int> myVector; vector<int>::iterator fromVector; myVector v; v.push_back( 'c' ); for( fromVector = v.begin(); fromVector<v.end(); fromVector++ ) { cout << *fromVector << endl; } cin.get(); }
Linked List Example
Code:#include <iostream> #include <string> using namespace std; class myClass { private: int ID; string Name; public: myClass * pNext; void cRecord( int ID, string data ); string gRecord( int ID ); void sRecordID( int rID ){ ID = rID; } void sRecordData( string Data ){ Name = Data; } int gRecordID(){ return ID; } string gRecordData(){ return Name; } myClass(){ pNext = NULL; } }MYCLASS; myClass *_MyClass = &MYCLASS; myClass *pHead = NULL; myClass *pCurrent = NULL; myClass *pPrevious = NULL; void myClass::cRecord( int ID, string data ) { pCurrent = new myClass; // Create the new class if( pPrevious == NULL ){ pHead = pCurrent; // If it's the first one then set it to the header. } else{ pPrevious->pNext = pCurrent; //If not then setup the next data structure } pCurrent->sRecordID( ID ); pCurrent->sRecordData( data ); pPrevious = pCurrent; // Set the data from this pointer to the previous. } string myClass::gRecord( int ID ) { pCurrent = pHead; if( pCurrent == NULL ) { cout << "No records found."; } else{ while( pCurrent != NULL ) { if( pCurrent->gRecordID() == ID ){ return pCurrent->gRecordData(); } else{ pCurrent = pCurrent->pNext; } } } } int main() { _MyClass->cRecord( 0, "Jackass" ); _MyClass->cRecord( 1, "Normajean" ); cout << _MyClass->gRecord( 0 ) << endl << _MyClass->gRecord( 1 ); cin.get(); }
DLL Call/Reference Example
Code:#include <iostream> #include <windows.h> typedef void ( *SomeFunctionsFunc )( int ); int main() { SomeFunctionsFunc _TFunc; HINSTANCE hInstanceLibrary = LoadLibrary("ExampleDLL.dll"); if( hInstanceLibrary ) { _TFunc = (SomeFunctionsFunc) GetProcAddress( hInstanceLibrary, "TestFunction" ); if( _TFunc ) { _TFunc(); } else{ cout << "Failed to load function from DLL."; } FreeLibrary( hInstanceLibrary ); } else { std::cout << "Failed to load DLL."; } std::cin.get(); return 0; }
Custom string functions namespace. I got tired of getting
results back from the string functions and me not be able
to fully understand if I'm going to get 0 or -1 as my result.
Code:namespace _String { struct STRING_DATA { bool StringFound; } String_Data; struct STRING_DATA *pString_Data = &String_Data; void String_Data_FLUSH(){ pString_Data->StringFound = 0; } typedef unsigned long _ulong; typedef unsigned int _uint; typedef signed int _sint; typedef void _VOID; _ulong _size( string Str ); _ulong _find( string Str, string Find ); string _substr( string Str, _ulong Begin=0, _ulong End=0 ); string _scamble( string Str, _ulong Seed=0 ); bool _empty( string Str ); bool _validString( string Str ); bool _validCharacter( string Str ); bool _isAlpha( string Str ); bool _isNumber( string Str ); bool StrFound = 0; char ALPHA_LOWER_BANK[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; char ALPHA_UPPER_BANK[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; char NUM_BANK[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; char SYMBOL_BANK[32] = { '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '[', '{', ']', '}', '\\', '|', ';', ':', '\'', '"', ',', '<', '.', '>', '/', '?' }; // Return the size of a string _ulong _size(string Str) { _uint cnt = 0; while( 1 ){ if( Str[cnt] != NULL ){ ++cnt; } else{ break; } } return cnt; } // Find the starting location of a character within a string // [1][2][3][4][5][6][7] // FINDING [3][4][5] // [1][2][3][4][5][6][7] // [3][4][5] // [3][4][5] // [3][4][5] RETURN 3 _ulong _find( string Str, string Find ) { CHAR Single = '\0'; //_ulong strSize = _size( Str ); _ulong Cnt = 0; if( _size( Find ) == 1 ){ Single = Find[0]; while( 1 ){ if( Str[Cnt] == Single ){ pString_Data->StringFound = 1; break; } else{ ++Cnt; } } } else { _ulong BaseCnt=0, EndCnt=_size( Find ); while( 1 ) { if( _substr( Str, BaseCnt, EndCnt-1 ) == Find ){ Cnt = BaseCnt; pString_Data->StringFound = 1; break; } else{ ++BaseCnt; ++EndCnt; } } } return Cnt; } // Find the substring of a complete string string _substr( string Str, _ulong Begin, _ulong End ) { string _OUT; _ulong Cnt = 0; while( 1 ) { if( Cnt >= Begin && Cnt <= End ){ _OUT += Str[Cnt]; } else{ if( Cnt == _size( Str ) ){ break; } } ++Cnt; } return _OUT; } bool _empty( string Str ) { if( _size( Str ) == 0 ){ return 1; } else{ return 0; } } bool _validString( string Str ) { if( _size( Str ) > 1 ){ return 1; } else{ return 0; } } bool _validCharacter( string Str ) { if( _size( Str ) == 1 ){ return 1; } else{ return 0; } } bool _isAlpha( string Str ) { _ulong Cnt = 0; bool Click = 0; if( _validCharacter( Str ) == 0 ){ Click = 0; } else{ while( Cnt < 27 ){ if( Str[0] == ALPHA_LOWER_BANK[Cnt] || Str[0] == ALPHA_UPPER_BANK[Cnt] ){ Click = 1; } ++Cnt; } } return Click; } }
Just some simple operation functions.
Code:namespace _Operations { bool _xor( bool a, bool b ); bool _xxor( bool a, bool b, bool c ); bool qSwitch( bool Switch ); bool _xor( bool a, bool b ){ return ( a || b ) && !(a && b ); } bool _xxor( bool a, bool b, bool c ){ return ( a || b || c ) && !( a && b && c ); } bool qSwitch( bool Switch ){ if( Switch == 0 ){ return 1; } else{ return 0; } } }
Just some common answers for when dealing with files.
The function names explain what they do.
Code:unsigned int FGetSize(const char* sFileName) { std::ifstream f; f.open( sFileName, std::ios_base::binary | std::ios_base::in ); if( !f.good() || f.eof() || !f.is_open() ) { return 0; } f.seekg( 0, std::ios_base::beg ); std::ifstream::pos_type begin_pos = f.tellg(); f.seekg( 0, std::ios_base::end ); return static_cast <unsigned int> ( f.tellg() - begin_pos ); } unsigned long FGetNumLines( const char* sFileName ) { unsigned long Lines = 0; string Temp; ifstream file; file.open( sFileName ); while( file ){ getline( file, Temp ); Lines++; Temp = ""; } if( Lines > 0 ){ Lines -= 1; } else{ Lines = 0; } return Lines; } bool FCombine(string AppendingFile, string Addition) { HANDLE hFile; HANDLE hAppend; DWORD dwBytesRead, dwBytesWritten, dwPos; BYTE buff[4096]; hFile = CreateFile( TEXT( Addition.c_str() ), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( hFile == INVALID_HANDLE_VALUE ) { return 0; } hAppend = CreateFile( TEXT( AppendingFile.c_str() ), FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if( hAppend == INVALID_HANDLE_VALUE ) { return 0; } do { if( ReadFile(hFile, buff, sizeof(buff), &dwBytesRead, NULL) ) { dwPos = SetFilePointer(hAppend, 0, NULL, FILE_END); LockFile(hAppend, dwPos, 0, dwBytesRead, 0); WriteFile(hAppend, buff, dwBytesRead, &dwBytesWritten, NULL); UnlockFile(hAppend, dwPos, 0, dwBytesRead, 0); } }while( dwBytesRead == sizeof(buff) ); CloseHandle(hFile); CloseHandle(hAppend); return 1; } bool FCopy( string From, string To ) { unsigned int WholeSize = FGetSize( From.c_str() ); unsigned int HalfSize = WholeSize / 2; unsigned int Combined = WholeSize + HalfSize; char *memblock; unsigned int num_of_bytes = Combined; memblock = new char [num_of_bytes]; //source file ifstream src( From.c_str(),ios::in | ios::binary ); //dest file ofstream dest( To.c_str(),ios::app | ios::binary ); if(!src.is_open()){ return 0; } else { while(true) { src.read( memblock, num_of_bytes ); num_of_bytes = src.gcount(); if( num_of_bytes == 0 ) break; dest.write( memblock,num_of_bytes ); } return 1; } src.close(); dest.close(); delete memblock; }
An example of a linked list. This has functions to add,
remove, and alter records.
Code:namespace __LL_DB { class Database { private: unsigned int recordID; string recordData; public: Database * pNext; void Enter_Record( unsigned int ID=0, string Data="" ); void Alter_Record( unsigned int ID=0, string Data="" ); string Get_Record( unsigned int ID=0 ); void Delete_Record( unsigned int ID=0 ); void Map_Database(); void setRecordID( unsigned int ID ){ recordID = ID; } void setRecordData( string Data ){ recordData = Data; } unsigned int getRecordID(){ return recordID; } string getRecordData(){ return recordData; } Database(){ pNext = NULL; } }; Database *pHead = NULL; Database *pCurrent = NULL; Database *pPrevious = NULL; void Database::Enter_Record( unsigned int ID, string Data ) { pCurrent = new Database; if( pPrevious == NULL ){ pHead = pCurrent; } else{ pPrevious->pNext = pCurrent; } pCurrent->setRecordID( ID ); pCurrent->setRecordData( Data ); pPrevious = pCurrent; } void Database::Alter_Record( unsigned int ID, string Data ) { pCurrent = pHead; if( pCurrent == NULL ){ } else{ while( pCurrent != NULL ){ if( pCurrent->getRecordID() == ID ){ if( Data == pCurrent->getRecordData() ){} else{ pCurrent = pHead->pNext; delete pHead; } } else{ pCurrent = pCurrent->pNext; } } Enter_Record( ID, Data ); } } string Database::Get_Record( unsigned int ID ) { pCurrent = pHead; if( pCurrent == NULL ){ cout << "No records found."; } else{ while( pCurrent != NULL ){ if( pCurrent->getRecordID() == ID ){ return pCurrent->getRecordData(); } else{ pCurrent = pCurrent->pNext; } } } } void Database::Delete_Record( unsigned int ID ) { pCurrent = pHead; if( pCurrent == NULL ){ } else{ while( pCurrent != NULL ){ if( pCurrent->getRecordID() == ID ){ pCurrent = pHead->pNext; delete pHead; } else{ pCurrent = pCurrent->pNext; } } } pHead=NULL; pCurrent=NULL; pPrevious=NULL; } }
And finally something I was working on.... I don't know what
its purpose was exactly...... probably was just sleep deprived
when I made it and shoved a bunch of cool crap together.....
But it works!! lol that it does....
Code:#include <vector.h> #define _NULL "NULL" using namespace _String; using namespace _Operations; using namespace CONSOLE; //using namespace FILE_STREAM; namespace __Variable_Funcs { _ulong ScriptLines; void LoadFile(); void CODE_Decipher( string Code ); // Variable functions /* Create a variable for later use */ void CreateVariable( string Name, string Data, bool Global ); /* Get the value of the specified variable */ string GetVariable( string Name, bool Global ); /* Delete the variable specified */ void DestroyVariable( string Name, bool Global ); /* Set a specified value to the specified variable */ void SetVariable( string Name, string Data, bool Global ); /* Set the current working function */ void sCurrentFunction( char *name, char *Args, short NumOfArgs, bool ReturningValue, _ulong BlockNumber); /* Gets the current working function */ char *gCurrentFunction(); /* Get the current working function arguments */ char *gCurrentFunctionArguments(); /* Destroys the current working function */ void DestroyCurrentFunction(); /* Creates an image of any given instance of any/all active variables and functions */ void GenerateMemoryDirectory(); // Data structure for the data pool variable struct DATA_POOL { string _dpVar; }_dPool; struct DATA_POOL *_dpool = &_dPool; // Function to set the data pool variable. ALWAYS USE STRING // a template was used with istringstream to ensure that the // user always uses a string and no other variable type. template< class __in__dPool > __in__dPool SetDataPool( __in__dPool VAR ) { istringstream strout( VAR ); strout >> _dpool->_dpVar; } // Function to get the data pool variable. You set the // data type here. // EX: GetDataPool<float> (); template< class __out__dPool > __out__dPool GetDataPool() { __out__dPool VAR; istringstream strin( _dpool->_dpVar ); strin >> VAR; return VAR; }; /* -------------------------------------------------------------- Current playing field. Holds current events, active variables, and functions. -------------------------------------------------------------- */ // Setup the current playing field struct CODE_FIELD { string cLocalVariable, cLValue; // ACTIVE VARIABLE TYPE string cGlobalVariable, cGValue; // INNACTIVE VARIABLE TYPE string cLocalFunction, cLFValue; // ACTIVE FUNCITON TYPE string cGlobalFunction, cGFValue; // INNACTIVE FUNTION TYPE } CField; struct CODE_FIELD *_CField = &CField; /* Local Variable Vectors */ typedef vector<string> cLocalVariables; // Local variable names typedef vector<string> cLocalValues; // Local variable values cLocalVariables clVars; cLocalValues clVals; /* Global Variable Vectors */ typedef vector<string> cGlobalVariables; // Global variable names typedef vector<string> cGlobalValues; // Global variable values cGlobalVariables glVars; cGlobalValues glVals; /* File Buffer Vectors */ typedef vector<string> __FILE_Outstream; typedef vector<string> __FILE_Instream; __FILE_Outstream _FoStream; __FILE_Instream _FiStream; /* File Buffer Data structure */ struct __FILE_STRUCTURE { _ulong NumberOfCells; // Number of known/valid/accessable cells within the File Buffer vector _ulong CurrentCell; // The current cell within the File Buffer vector string CurrentDataType; // The current working datatype for the open stream bool Action_Outstream; // Is the Outstream currently active/allowed [1 | 0] bool Action_Instream; // Is the Instream currently active/allowed [1 | 0] bool StreamCurrentlyOpen; // Is the file stream actually currently open? [1 | 0] ( Debugging purposes ) char *StreamName; // The name of the current open stream ( Can use default, names are used for Debugging purposes ) char *StreamArguments; // Stream arguments for handling the currently parsed stream. } __FILE_STRUCT; struct __FILE_STRUCTURE *__FStream_Data = &__FILE_STRUCT; /* Build the default configurations for the FILE STRUCTURE buffer to reference later */ void __FILE_STREAM_BUILD() { __FStream_Data->NumberOfCells = _FoStream.size() + _FiStream.size(); __FStream_Data->CurrentCell = 0; __FStream_Data->Action_Outstream = 0; __FStream_Data->Action_Instream = 0; __FStream_Data->StreamName = "DEFAULT_IOS"; __FStream_Data->StreamArguments = _NULL; } /* FILE STREAM TREE CLASS -------------------------- { enum }-------------------------- NumberOfCells - Allows for changing the config for the number of cells currently used/allowed CurrentCell - Allows for changing the config for the current cell being used/allocated Action_Outstream - Allows for changing the config for wether or not the outstream is activated/allowed Action_Instream - Allows for changing the config for wether or not the instream is activated/allowed -------------------------- { Functions }-------------------------- void setStreamName( char *strmName ); - Allows for changing the name of the currently active stream. void setStreamArguments( char *strmArgs ); - Allows for changing the arguments of the currently active stream. */ class __FILE_STREAM_TREE_CLASS { public: enum _fSet { NumberOfCells, CurrentCell, Action_Outstream, Action_Instream }; void setStreamName( char *strmName ); void setStreamArguments( char *strmArgs ); }__FILE_STREAM_TREE_d; class __FILE_STREAM_TREE_CLASS *__FStreamTree = & __FILE_STREAM_TREE_d; /* FILE STREAM MAIN CLASS -------------------------- { Functions }-------------------------- bool LoadFile( string FileName, bool binaryFile ); - Loads a file into memory ( a vector ) to be read/used later. string GetBuffer(); - Loads the input file buffer ( from LoadFile(); ) into a string and returns the value via the function. */ class __FILE_STREAM_CLASS { public: bool LoadFile( string FileName, bool binaryFile ); string GetBuffer(); }__FILE_STREAM_CLASS_d; class __FILE_STREAM_CLASS *__FStream = & __FILE_STREAM_CLASS_d; bool __FILE_STREAM_CLASS::LoadFile( string FileName, bool binaryFile ) { if( _size( FileName ) != 0 ) { ifstream _IFile; if( binaryFile == 0 ) { _IFile.open( FileName.c_str(), ios::in ); if( ! _IFile ){ return 0; } else{ string tempBuffer; while( _IFile.good() ) { getline( _IFile, tempBuffer ); _FiStream.push_back( tempBuffer ); tempBuffer = ""; } return 1; } } else { _IFile.open( FileName.c_str(), ios::in | ios::binary ); if( ! _IFile ){ return 0; } else{ string tempBuffer; while( _IFile.good() ) { getline( _IFile, tempBuffer ); _FiStream.push_back( tempBuffer ); tempBuffer = ""; } return 1; } } _IFile.close(); } else{ return 0; } } string __FILE_STREAM_CLASS::GetBuffer() { string ReturnBuffer; vector<string>::iterator fromBuffer; for( fromBuffer = _FiStream.begin() ; fromBuffer < _FiStream.end(); fromBuffer ++ ) { ReturnBuffer = ReturnBuffer + *fromBuffer; } return ReturnBuffer; } /* Function definition */ struct FUNCTION_DEFINITION { char *FuncName, *FuncArgs; // Name and arguments for the function short NumberOfArguments; // Number of arguments bool ReturningValue; // True or False for returning a value _ulong BlockNumber; // Number of the function } FDefinition; struct FUNCTION_DEFINITION *_FDefinition = &FDefinition; /* Base function to set the current wokring function */ void sCurrentFunction( char *name, char *Args, short NumOfArgs, bool ReturningValue, _ulong BlockNumber=1) { _FDefinition->FuncName = name; _FDefinition->FuncArgs = Args; _FDefinition->NumberOfArguments = NumOfArgs; _FDefinition->BlockNumber += BlockNumber; } /* Base function to get the current working function */ char *gCurrentFunction(){ return _FDefinition->FuncName; } /* Base function to get the current working function's arguments */ char *gCurrentFunctionArguments(){ return _FDefinition->FuncName; } /* Base function to destroy the current wokring function */ void DestroyCurrentFunction() { _FDefinition->FuncName = NULL; _FDefinition->FuncArgs = NULL; _FDefinition->NumberOfArguments = NULL; _FDefinition->ReturningValue = NULL; _FDefinition->BlockNumber = NULL; } void LoadFile() { ScriptLines = FILE_STREAM::File.FGetNumLines( fName ); string Code[ScriptLines]; ifstream file; file.open( fName ); for( _ulong j=0; j<ScriptLines; j++ ) { getline( file, Code[j] ); } for( _ulong j=0; j<ScriptLines; j++ ) { CODE_Decipher( Code[j] ); } } /* Base function to create a variable */ void CreateVariable( string Name, string Data, bool Global=0 ) { if( Global == 0 ) { clVars.push_back( Name ); clVals.push_back( Data ); } } /* Base function to return the value of a specified variable */ string GetVariable( string Name, bool Global=0 ) { double size = clVars.size(); string Value = _NULL; if( Global == 0 ) { for( double j=0; j<size; j++ ) { if( clVars[j] == Name ){ Value = clVals[j]; break; } } } return Value; } /* Base function to set a value to a specified variable */ void SetVariable( string Name, string Data, bool Global=0 ) { DestroyVariable( Name, Global ); CreateVariable( Name, Data, Global ); } /* Base function to destroy a variable */ void DestroyVariable( string Name, bool Global=0 ) { double size = clVars.size(); if( Global == 0 ) { for( double j=0; j<size; j++ ) { if( clVars[j] == Name ){ clVars.erase( clVars.begin()+j ); clVals.erase( clVals.begin()+j ); break; } } } } // Function to create a directory of each variable that's currently in use. void GenerateMemoryDirectory() { double cSize = clVars.size(); _CField->cLocalVariable = clVars[cSize-1]; _CField->cLValue = clVals[cSize-1]; _CField->cLocalFunction = gCurrentFunction(); } void CODE_Decipher( string Code ) { } // scr_ (screened) bool scr_CreateFile() { if( GetVariable( "#fcreate_nameStr" ) == "NULL" ) { cout << "ERROR: Cannot create file -- name string buffer is NULL"; return 0; } else { if( FILE_STREAM::File.FCreate( GetVariable( "#fcreate_nameStr" ) ) == 1 ) { return 1; }else{ return 0; } } } // DUMMY ENUMERATOR /* Used for all of the main enumerated types. When a new type is created, it must be declared here aswell. */ enum _Void { _fCREATE, _fDELETE, _fWRITE, _fWRITELINE, _fMOVE, _fCOPY, _fRENAME, _fGETSIZE, _fGETLINES, _varCREATE, _varDELETE, _varUPDATE, _varCOMBINE, _varADD, _varSUBTRACT, _varMULTIPLY, _varDIVIDE, _varCAST, _varSQUAREROOT }; string Void_sOperatorTypes[] = { "FILE_CREATE", "FILE_DELETE", "FILE_WRITE", "FILE_WRITELINE", "FILE_MOVE", "FILE_COPY", "FILE_RENAME", "FILE_GETSIZE", "FILE_GETLINES", "VAR_CREATE", "VAR_DELETE", "VAR_UPDATE", "VAR_COMBINE", "VAR_ADD", "VAR_SUBTRACT", "VAR_MULTIPLY", "VAR_DIVIDE", "VAR_CAST", "VAR_SQUAREROOT" }; // Complete list of all of the operations allowed by the script enum OPERATIONS { _FILE, _VARIABLE, _SYSCOMMAND }; // Handler names for each operation string OPERATOR_TYPES[] = { "FILE", "VARIABLE", "SYSTEM COMMAND" }; // Complete list of sub-operations allowed by the script by // each main operation listed above. /* SUB OPERATIONS FOR: _FILE ------------------------- _fOpCREATE :: Will create a specified file _fOpDELETE :: Will delete a specified file _fOpWRITE :: Will write to a specified file _fOpWRITELINE :: Will write a line to a specified file _fOpMOVE :: Will move the specified file _fOpCOPY :: Will copy the specified file _fOpRENAME :: Will rename the specified file _fOpGETSIZE :: Will get the size of the specified file _fOpGETLINES :: Will get the number of lines within the specified file */ enum FILE_sOperations { _fOpCREATE, _fOpDELETE, _fOpWRITE, _fOpWRITELINE, _fOpMOVE, _fOpCOPY, _fOpRENAME, _fOpGETSIZE, _fOpGETLINES }; // SUB Operation handler names for the _FILE operation string FILE_sOperatorTypes[] = { "FILE_CREATE", "FILE_DELETE", "FILE_WRITE", "FILE_WRITELINE", "FILE_MOVE", "FILE_COPY", "FILE_RENAME", "FILE_GETSIZE", "FILE_GETLINES" }; /* SUB OPERATIONS FOR: _VARIABLE ----------------------------- _VARsOpCREATE :: Will create a new variable _VARsOpDELETE :: Will delete a variable _VARsOpUPDATE :: Will update the value of a variable _VARsOpCOMBINE :: Will combine two string variables _VARsOpADD :: Will add two numerical variables _VARsOpSUBTRACT :: Will find the difference between two numerical variables _VARsOpMULTIPLY :: Will multiply two numerical variables _VARsOpDIVIDE :: Will divide a numerical variable _VARsOpCAST :: Will moprh a variable into a different type _VARsOpSQUAREROOT :: Will find the square root of a numerical variable */ enum VAR_sOperations { _VARsOpCREATE, _VARsOpDELETE, _VARsOpUPDATE, _VARsOpCOMBINE, _VARsOpADD, _VARsOpSUBTRACT, _VARsOpMULTIPLY, _VARsOpDIVIDE, _VARsOpCAST, _VARsOpSQUAREROOT }; // SUB Operation handler names for the _VARIABLE operation string VAR_sOperatorTypes[] = { "VAR_CREATE", "VAR_DELETE", "VAR_UPDATE", "VAR_COMBINE", "VAR_ADD", "VAR_SUBTRACT", "VAR_MULTIPLY", "VAR_DIVIDE", "VAR_CAST", "VAR_SQUAREROOT" }; // Insert operation type as argument, not raw value. // EX: SetOperation( _FILE ); void SetOperation( OPERATIONS OPS, _Void VOP ) { switch( OPS ) { case _FILE: switch( VOP ) { case _fCREATE: CreateVariable( "#fcreate_nameStr", "DummyFile.txt", 0 ); CreateVariable( "#fcreate_buffer", "This is just a test file" ); cout << "Creating test file ( DummyFile.txt ) "; FILE_STREAM::File.FCreate( GetVariable( "#fcreate_nameStr" ) ); FILE_STREAM::File.FWriteLine( GetVariable( "#fcreate_nameStr" ), GetVariable( "#fcreate_buffer" ) ); break; case _fDELETE: cout << Void_sOperatorTypes[VOP]; break; case _fWRITE: cout << Void_sOperatorTypes[VOP]; break; case _fWRITELINE: cout << Void_sOperatorTypes[VOP]; break; case _fMOVE: cout << Void_sOperatorTypes[VOP]; break; case _fCOPY: cout << Void_sOperatorTypes[VOP]; break; case _fRENAME: cout << Void_sOperatorTypes[VOP]; break; case _fGETSIZE: cout << Void_sOperatorTypes[VOP]; break; case _fGETLINES: cout << Void_sOperatorTypes[VOP]; break; }; break; case _VARIABLE: switch( VOP ) { case _varCREATE: cout << Void_sOperatorTypes[VOP]; break; case _varDELETE: cout << Void_sOperatorTypes[VOP]; break; case _varUPDATE: cout << Void_sOperatorTypes[VOP]; break; case _varCOMBINE: cout << Void_sOperatorTypes[VOP]; break; case _varADD: cout << Void_sOperatorTypes[VOP]; break; case _varSUBTRACT: cout << Void_sOperatorTypes[VOP]; break; case _varMULTIPLY: cout << Void_sOperatorTypes[VOP]; break; case _varDIVIDE: cout << Void_sOperatorTypes[VOP]; break; case _varCAST: cout << Void_sOperatorTypes[VOP]; break; case _varSQUAREROOT: cout << Void_sOperatorTypes[VOP]; break; }; break; }; } }; /* - Set current working function: sCurrentFunction( char *Name, char *Args, short NumOfArgs, bool ReturningValue, _ulong BlockNumber ); - Get current working function: gCurrentFunction(); - Create a variable CreateVariable( string Name, string Data, bool Global ); - Get a variable's data GetVariable( string Name, bool Global ); - Destroy a variable DestroyVariable( string Name, bool Global ); - Set an operation SetOperation( enum OperationName, enum SubOperation ); - Set the data pool SetDataPool<string> ( string VALUE ); - Get the data pool GetDataPool<DesiredDataType> (); */ /*int main() { sCurrentFunction( "MyCurrentFunction", "Arg1|Arg2|Arg3", 3, 1); //cout << gCurrentFunction(); CreateVariable( "MyVar", "Some data for the first variable.", 0 ); CreateVariable( "MyVar2", "Some more data for the second variable.", 0 ); cout << "\nGetting the value of MyVar: \n" << GetVariable( "MyVar" ) << "\n\nGetting the value of MyVar2: \n" << GetVariable( "MyVar2" ); DestroyVariable( "MyVar" ); cout << "\n\nDestroyed MyVar"; cout << "\n\nAttempting to get the value of MyVar: \n" << GetVariable( "MyVar" ) << "\n\nAttempting to get the value of MyVar2: \n" << GetVariable( "MyVar2" ); SetVariable( "MyVar2", "Well crap'ola", 0 ); cout << "\n\nSet the value of MyVar2 to: \n" << GetVariable( "MyVar2" ); GenerateMemoryDirectory(); cout << "\n\n\nMemory Directory Generated.\n"; cout << "\n\nWhat we got: " << "\n\nCurrent local variable: \n" << _CField->cLocalVariable << "\n\nCurrent local variable value: \n" << _CField->cLValue << "\n\nCurrent local function: \n" << _CField->cLocalFunction; Console._ELine(); SetOperation( _FILE, _fWRITE ); Console._ELine(); SetOperation( _FILE, _fGETSIZE ); SetDataPool<string> ("19"); // Use string ALWAYS Console._ELine(); cout << GetDataPool<char>(); // Type casting is done by using the following: // :Create the variable: CreateVariable( "CastedVariable", "50.8937", 0 ); // :Set the variable to the data pool: SetDataPool<string> ( GetVariable( "CastedVariable" ) ); // :Use the GetDataPool() function as an integer according to a template: cout << "Casted type from string to integer: \n" << GetDataPool<int>(); Console._ELine(); cin.get(); return 0; }*/


LinkBack URL
About LinkBacks




Reply With Quote





Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum