Nebula
Loading...
Searching...
No Matches
commandlineargs.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
15#include "util/array.h"
16#include "util/string.h"
17#include "math/vec4.h"
18#include "math/mat4.h"
19
20//------------------------------------------------------------------------------
21namespace Util
22{
24{
25public:
29 CommandLineArgs(const String& cmdLine);
31 CommandLineArgs(int argc, const char** argv);
33 const String& GetCmdName() const;
35 bool HasArg(const String& arg, const IndexT start = 0) const;
37 const String& GetString(const String& name, const String& defaultValue = "") const;
39 Util::Array<Util::String> GetStrings(const String& name, const String& defaultValue = "") const;
41 int GetInt(const String& name, int defaultValue = 0) const;
43 Util::Array<int> GetInts(const String& name, int defaultValue = 0) const;
45 float GetFloat(const String& name, float defaultValue = 0.0f) const;
47 Util::Array<float> GetFloats(const String& name, float defaultValue = 0.0f) const;
49 bool GetBool(const String& name, bool defaultValue=false) const;
51 Util::Array<bool> GetBools(const String& name, bool defaultValue = false) const;
53 bool GetBoolFlag(const String& name) const;
54 #if !__OSX__
56 Math::vec4 GetVec4(const String& name, const Math::vec4& defaultValue = Math::vec4()) const;
58 Util::Array<Math::vec4> GetVec4s(const String& name, const Math::vec4& defaultValue = Math::vec4()) const;
60 Math::mat4 GetMat4(const String& name, const Math::mat4& defaultValue = Math::mat4()) const;
62 Util::Array<Math::mat4> GetMat4s(const String& name, const Math::mat4& defaultValue = Math::mat4()) const;
63 #endif
64
66 bool IsEmpty() const;
68 SizeT GetNumArgs() const;
70 const String& GetStringAtIndex(IndexT index) const;
72 int GetIntAtIndex(IndexT index) const;
74 float GetFloatAtIndex(IndexT index) const;
76 bool GetBoolAtIndex(IndexT index) const;
77 #if !__OSX__
79 Math::vec4 GetVec4AtIndex(IndexT index) const;
81 Math::mat4 GetMat4AtIndex(IndexT index) const;
82 #endif
84 void AppendCommandString(const CommandLineArgs& otherArgs);
87
88private:
90 void Error(const String& argName) const;
92 int FindArgIndex(const String& argName, const IndexT start = 0) const;
94 void ParseIntoGroups(const Array<String>& Tokenized);
95
98};
99
100
101//------------------------------------------------------------------------------
104inline bool
106{
107 return this->args.Size() == 0;
108}
109
110//------------------------------------------------------------------------------
113inline const Dictionary<String, String>&
115{
116 return this->keyPairs;
117}
118
119} // namespace Util
120//------------------------------------------------------------------------------
Nebula's dynamic array class.
Definition array.h:60
const Dictionary< String, String > & GetPairs() const
get any key value pairs from args
Definition commandlineargs.h:114
void ParseIntoGroups(const Array< String > &Tokenized)
sort out any explicit key=value arguments into separate structure
Definition commandlineargs.cc:49
Util::Array< Math::mat4 > GetMat4s(const String &name, const Math::mat4 &defaultValue=Math::mat4()) const
get all mat4 values
Definition commandlineargs.cc:357
Math::vec4 GetVec4(const String &name, const Math::vec4 &defaultValue=Math::vec4()) const
get vec4 value
Definition commandlineargs.cc:298
float GetFloatAtIndex(IndexT index) const
get float value at index
Definition commandlineargs.cc:413
bool IsEmpty() const
returns true if the argument list is empty
Definition commandlineargs.h:105
bool HasArg(const String &arg, const IndexT start=0) const
return true if arg exists
Definition commandlineargs.cc:90
float GetFloat(const String &name, float defaultValue=0.0f) const
get float value
Definition commandlineargs.cc:202
Math::mat4 GetMat4(const String &name, const Math::mat4 &defaultValue=Math::mat4()) const
get mat4 value
Definition commandlineargs.cc:341
Util::Array< float > GetFloats(const String &name, float defaultValue=0.0f) const
get all float values
Definition commandlineargs.cc:218
SizeT GetNumArgs() const
get number of arguments (exluding command name)
Definition commandlineargs.cc:385
int FindArgIndex(const String &argName, const IndexT start=0) const
find index of argument, fails hard with error msg if not found
Definition commandlineargs.cc:101
bool GetBoolFlag(const String &name) const
get bool flag (args only needs to exist to trigger as true)
Definition commandlineargs.cc:288
int GetIntAtIndex(IndexT index) const
get int value at index
Definition commandlineargs.cc:404
void Error(const String &argName) const
put out an error
Definition commandlineargs.cc:69
Math::vec4 GetVec4AtIndex(IndexT index) const
get vec4 value at index
Definition commandlineargs.cc:432
Util::Array< bool > GetBools(const String &name, bool defaultValue=false) const
get all bool values
Definition commandlineargs.cc:261
const String & GetString(const String &name, const String &defaultValue="") const
get string value
Definition commandlineargs.cc:116
void AppendCommandString(const CommandLineArgs &otherArgs)
append other command string
Definition commandlineargs.cc:451
const String & GetCmdName() const
get the command name
Definition commandlineargs.cc:79
const String & GetStringAtIndex(IndexT index) const
get string argument at index
Definition commandlineargs.cc:395
Array< String > args
Definition commandlineargs.h:96
int GetInt(const String &name, int defaultValue=0) const
get int value
Definition commandlineargs.cc:159
Util::Array< int > GetInts(const String &name, int defaultValue=0) const
get all int values
Definition commandlineargs.cc:175
bool GetBool(const String &name, bool defaultValue=false) const
get bool value (key=value)
Definition commandlineargs.cc:245
CommandLineArgs()
default constructor
Definition commandlineargs.cc:18
Math::mat4 GetMat4AtIndex(IndexT index) const
get mat4 value at index
Definition commandlineargs.cc:441
Dictionary< String, String > keyPairs
Definition commandlineargs.h:97
bool GetBoolAtIndex(IndexT index) const
get bool value at index
Definition commandlineargs.cc:422
Util::Array< Math::vec4 > GetVec4s(const String &name, const Math::vec4 &defaultValue=Math::vec4()) const
get all vec4 values
Definition commandlineargs.cc:314
Util::Array< Util::String > GetStrings(const String &name, const String &defaultValue="") const
get all string values
Definition commandlineargs.cc:132
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
A 4x4 single point precision float matrix.
Definition mat4.h:49
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition String.cs:8
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48