#include "StdAfx.h" #include "Options_m.h" #include <stdlib.h> using namespace System::Runtime::InteropServices; p4dn::Options::Options(void) { _options = new ::Options(); _parseSuccess = false; } p4dn::Options::~Options(void) { CleanUp(); } void p4dn::Options::Dispose() { System::GC::SuppressFinalize(this); CleanUp(); } void p4dn::Options::CleanUp() { // cleanup all the dynamic memory if (_argsArray != NULL) { for (int i = 0; i < _argc; ++i) { Marshal::FreeHGlobal( _argsArray[i] ); } delete _argsArray; } _argsArray = NULL; if (_optionDefinition != NULL) { Marshal::FreeHGlobal(_optionDefinition); } if (_options != NULL ) delete _options; _options = NULL; } void p4dn::Options::Parse(System::String* args[], System::String* opts, Flags flags) { // reset everything if this is a repeat call if (_argsArray != NULL) { CleanUp(); _options = new ::Options(); } // convert managed array to char** _argsArray = new char* [ args->Length ]; _argc = args->Length; for (int i = 0; i < args->Length; ++i) { _argsArray[i] = (char *)(void *) Marshal::StringToHGlobalAnsi( args[i] ); } // convert options string _optionDefinition = (char *)(void *) Marshal::StringToHGlobalAnsi(opts); int argc = _argc; Error* e = new Error(); ErrorId usage = { E_FAILED, "Usage: parse optionstring flag args" }; // we need to store off the original pointer, b/c it will get lost char** args2 = _argsArray; _options->Parse(argc, args2, _optionDefinition, flags, usage, e ); if( e->Test() ) { _parseSuccess = false; CleanUp(); _options = new ::Options(); } else { _parseSuccess = true; } delete e; } System::String* p4dn::Options::GetValue(System::Char opt) { System::String* ret = NULL; if (!_parseSuccess) { throw new System::Exception("Can't obtain value. Parse was unsuccessful."); } return _options->GetValue(opt,0)->Text(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 5830 | Shawn Hladky | P4.Net: reorg to support release branches | ||
#2 | 5798 | Shawn Hladky |
P4.Net... still not ready for beta Added license to all files Added several doc files Misc bugs |
||
#1 | 5447 | Shawn Hladky | refactor, and added options class |