quick start:g++ [flags ...] commandline ... -l /isip/tools/lib/$ISIP_BINARY/lib_shell.a #include <CommandLine.h> ~CommandLine(); CommandLine(); CommandLine(const CommandLine& arg); boolean setHelp(const unichar* help_message); String& addOptionParam(Long& var, const String& param, long def_value); boolean parse(int argc, const char** argv); long getOptionIndex(const String& param_name);
description:String com_str(L"foo.exe -swap -sf 7000.0 -help"); CommandLine cmdl; // add an swap flag // String flag_param(L"swap"); Boolean swap; cmdl.addFlagParam(swap, flag_param); // add a sample frequency // String sf_param(L"sf"); Float sf; cmdl.addOptionParam(sf, sf_param, (float)8000.0); // parse the commandline // cmdl.parse(com_str); // test the swap flag // if (swap) { Console::put(L"swap flag specified"); } // print the sample frequency // sf.debug(L"sample frequency");
static const String CLASS_NAME = L"CommandLine";
static const String DEF_PARAM_PREFIX = L"-";
static const String DEF_PARAM_SPACE = L" ";
static const String DEF_PARAM_DEBUG = L"debug_level";
static const String DEF_PARAM_LFILE = L"log_file";
static const String DEF_PARAM_PFILE = L"parameter_file";
static const String DEF_PARAM_TYPE = L"type";
static const String DEF_PARAM_VERBOSITY = L"verbosity";
static const String DEF_PARAM_DIRECTORY = L"directory";
static const String DEF_PARAM_BASENAME = L"basename";
static const String DEF_PARAM_EXTENSION = L"extension";
static const String DEF_PARAM_PRESERVE = L"preserve";
static const String DEF_PARAM_SUFFIX = L"suffix";
static const String DEF_PARAM_ECHOC = L"echo_command_line";
static const String DEF_PARAM_HELP = L"help";
static const String DEF_PARAM_USAGE = L"usage";
static const String DEF_PARAM_VERSION = L"version";
static const long DEF_OBJECTS_SIZE = 100;
static const String COMMAND_STR = L"Command:";
static const String NO_VERSION_NAME = L"not released";
static const String VERSION_STR = L"Version: ";
static const String REPORT_STR_00 = L": processed ";
static const String REPORT_STR_01 = L" file(s), attempted ";
static const String REPORT_STR_02 = L" file(s).\n";
static const long OPT_INDEX_SDB = 99999;
static Filename DEF_EMPTY = L"";
static Filename DEF_LFILE_NAME = L"-";
static const long ERR = 45000;
static const long ERR_OPT = 45001;
static const long ERR_OPTAMB = 45002;
static const long ERR_OPTDUPL = 45003;
static const long ERR_OPTMULT = 45004;
static const long ERR_OPTARG = 45005;
static const long ERR_OPTPARS = 45006;
String prog_name_d;
Vector<String> options_d;
Vector<String> types_d;
Vector<Boolean> used_d;
Vector<String> args_d;
Vector<String> values_d;
Boolean echoc_flag_d;
Boolean help_flag_d;
Boolean usage_flag_d;
Boolean version_flag_d;
String help_msg_d;
String usage_msg_d;
String version_msg_d;
String expanded_d;
Sdb* sdb_d;
long objects_size_d;
void** objects_d;
boolean usage_printed_d;
static boolean test_mode_d;
Integral::DEBUG debug_level_d;
static MemoryManager mgr_d;
static const String& name();
static boolean diagnose(Integral::DEBUG debug_level);
boolean setDebug(Integral::DEBUG level);
boolean debug(const unichar* message) const;
~CommandLine();
CommandLine();
CommandLine(const CommandLine& arg);
boolean assign(const CommandLine& arg);
CommandLine& operator=(const CommandLine& arg);
these methods are omitted because CommandLine object can not write itself to an Sof file
boolean eq(const CommandLine& arg) const;
static void* operator new(size_t size);
static void* operator new[](size_t size);
static void operator delete(void* ptr);
static void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);
CommandLine(Sdb& arg);
boolean assign(const String& arg);
boolean setHelp(const unichar* help_message);
boolean setUsage(const unichar* usage_message);
boolean setVersion(const unichar* version_message);
boolean setIdent(const char* rev_str, const char* name_str, const char* date_str);
boolean setSdb(Sdb& arg_a);
boolean printUsage();
boolean printHelp() const;
boolean printVersion() const;
boolean printCommandLine() const;
static boolean printFinalReport(const String& prog_name, long num_completed, long num_attempted);
boolean printFinalReport(long num_completed, long num_attempted) const;
boolean addFlagParam(Boolean& var, const String& param);
boolean addOptionParam(File::TYPE& var, const String& param, const File::TYPE& def_value = File::DEF_TYPE);
boolean addOptionParam(String& var, const String& param, const String& def_value);
boolean addOptionParam(Filename& var, const String& param, const Filename& def_value);
boolean addOptionParam(DebugLevel& var, const String& param = DebugLevel::DEF_PARAM, Integral::DEBUG def_value = Integral::DEF_DEBUG);
boolean addOptionParam(Byte& var, const String& param, byte def_value);
boolean addOptionParam(Short& var, const String& param, short def_value);
boolean addOptionParam(Long& var, const String& param, long def_value);
boolean addOptionParam(Llong& var, const String& param, llong def_value);
boolean addOptionParam(Ushort& var, const String& param, ushort def_value);
boolean addOptionParam(Ulong& var, const String& param, ulong def_value);
boolean addOptionParam(Ullong& var, const String& param, ullong def_value);
boolean addOptionParam(Float& var, const String& param, float def_value);
boolean addOptionParam(Double& var, const String& param, double def_value);
boolean addOptionParam(SingleLinkedList<String>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Filename>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Byte>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Short>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Long>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Llong>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Ushort>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Ulong>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Ullong>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Float>& var, const String& param);
boolean addOptionParam(SingleLinkedList<Double>& var, const String& param);
const String& getProgName() const;
boolean getArgument(String& arg_a, long ordinal_number) const;
long numArguments() const;
boolean getExpanded(String& arg);
long getOptionIndex(const String& opt_name , boolean prefix = false);
boolean getValue(String& value, const String& opt_name, boolean prefix = false);
boolean isPresent(const String& opt_name, boolean prefix = false) const;
boolean parse(int argc, const char** argv);
boolean parse(const String& line);
boolean addOptionParam(void* var, const String& name, const String& param);
boolean isMultipleParam(long index);
foo.exe -nbytes 4 -mode stereo file.rawThe code below demonstrates how to initialize a command line object to process this command line:
// declare a command line, and a string containing an example command line // CommandLine cmdl; String str(L"foo.exe -nbytes 4 -mode stereo file.raw"); // add the mode // String mode_param(L"mode"); String mode_def(L"play"); String mode; cmdl.addOptionParam(mode, mode_param, mode_def); // add the number of bytes // String nbytes_param(L"nbytes"); Long nbytes; cmdl.addOptionParam(nbytes, nbytes_param, (long)2); // set the help message // cmdl.setHelp(#include "dbg_help.help"); // parse the commandline // cmdl.parse(str); // print the mode // mode.debug(L"mode"); // get number of unused arguments // Long num_arg = (long)cmdl.numArguments(); // get unused arguments // String arg; cmdl.getArgument(arg, 0); // print the number of unused arguments // num_arg.debug(L"numArguments"); // print the unused argument // arg.debug(L"getArgument");