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);
85
86private:
88 void Error(const String& argName) const;
90 int FindArgIndex(const String& argName, const IndexT start = 0) const;
91
93};
94
95
96//------------------------------------------------------------------------------
99inline bool
101{
102 return this->args.Size() == 0;
103}
104
105} // namespace Util
106//------------------------------------------------------------------------------
Nebula's dynamic array class.
Definition array.h:60
A universal cmd line argument parser.
Definition commandlineargs.h:24
Util::Array< Math::mat4 > GetMat4s(const String &name, const Math::mat4 &defaultValue=Math::mat4()) const
get all mat4 values
Definition commandlineargs.cc:336
Math::vec4 GetVec4(const String &name, const Math::vec4 &defaultValue=Math::vec4()) const
get vec4 value
Definition commandlineargs.cc:277
float GetFloatAtIndex(IndexT index) const
get float value at index
Definition commandlineargs.cc:392
bool IsEmpty() const
returns true if the argument list is empty
Definition commandlineargs.h:100
bool HasArg(const String &arg, const IndexT start=0) const
return true if arg exists
Definition commandlineargs.cc:69
float GetFloat(const String &name, float defaultValue=0.0f) const
get float value
Definition commandlineargs.cc:181
Math::mat4 GetMat4(const String &name, const Math::mat4 &defaultValue=Math::mat4()) const
get mat4 value
Definition commandlineargs.cc:320
Util::Array< float > GetFloats(const String &name, float defaultValue=0.0f) const
get all float values
Definition commandlineargs.cc:197
SizeT GetNumArgs() const
get number of arguments (exluding command name)
Definition commandlineargs.cc:364
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:80
bool GetBoolFlag(const String &name) const
get bool flag (args only needs to exist to trigger as true)
Definition commandlineargs.cc:267
int GetIntAtIndex(IndexT index) const
get int value at index
Definition commandlineargs.cc:383
void Error(const String &argName) const
put out an error
Definition commandlineargs.cc:48
Math::vec4 GetVec4AtIndex(IndexT index) const
get vec4 value at index
Definition commandlineargs.cc:411
Util::Array< bool > GetBools(const String &name, bool defaultValue=false) const
get all bool values
Definition commandlineargs.cc:240
const String & GetString(const String &name, const String &defaultValue="") const
get string value
Definition commandlineargs.cc:95
void AppendCommandString(const CommandLineArgs &otherArgs)
append other command string
Definition commandlineargs.cc:430
const String & GetCmdName() const
get the command name
Definition commandlineargs.cc:58
const String & GetStringAtIndex(IndexT index) const
get string argument at index
Definition commandlineargs.cc:374
Array< String > args
Definition commandlineargs.h:92
int GetInt(const String &name, int defaultValue=0) const
get int value
Definition commandlineargs.cc:138
Util::Array< int > GetInts(const String &name, int defaultValue=0) const
get all int values
Definition commandlineargs.cc:154
bool GetBool(const String &name, bool defaultValue=false) const
get bool value (key=value)
Definition commandlineargs.cc:224
CommandLineArgs()
default constructor
Definition commandlineargs.cc:18
Math::mat4 GetMat4AtIndex(IndexT index) const
get mat4 value at index
Definition commandlineargs.cc:420
bool GetBoolAtIndex(IndexT index) const
get bool value at index
Definition commandlineargs.cc:401
Util::Array< Math::vec4 > GetVec4s(const String &name, const Math::vec4 &defaultValue=Math::vec4()) const
get all vec4 values
Definition commandlineargs.cc:293
Util::Array< Util::String > GetStrings(const String &name, const String &defaultValue="") const
get all string values
Definition commandlineargs.cc:111
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.h:50
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48