Base class for command-line flag handling 더 자세히 ...
#include <flag.hpp>
Public 타입 | |
| enum | res { MATCH , EXIT_PROGRAM , NOT_MATCH } |
Public 멤버 함수 | |
| virtual const nchar * | getName () const =0 |
| virtual const nchar * | getDescription () const =0 |
| virtual res | take (interpreter &ip, starter &s, cli &c, flagArgs &a, errReport &rpt) const |
| nbool | canTake (const std::string &pattern) const |
by::instance(으)로부터 상속된 Public 멤버 함수 | |
| instance (id newId) | |
| instance (const me &rhs) | |
| me & | operator= (const me &rhs)=default |
| void * | operator new (size_t sz) noexcept |
| void | operator delete (void *pt, size_t sz) noexcept |
| virtual id | getId () const |
| virtual nbool | isHeap () const |
| Checks if this instance is allocated on the heap. | |
| const life * | getBindTag () const |
| Returns a pointer to the associated life object for reference counting. | |
by::typeProvidable(으)로부터 상속된 Public 멤버 함수 | |
| nbool | operator== (const me &rhs) const |
| nbool | operator!= (const me &rhs) const |
| virtual const type & | getType () const =0 |
| nbool | isSub (const type &it) const |
| nbool | isSub (const type *it) const BY_SIDE_FUNC(isSub) |
| nbool | isSub (const me &it) const |
| nbool | isSub (const me *it) const BY_SIDE_FUNC(isSub) |
| nbool | isSuper (const type &it) const |
| nbool | isSuper (const type *it) const BY_SIDE_FUNC(isSuper) |
| nbool | isSuper (const me &it) const |
| nbool | isSuper (const me *it) const BY_SIDE_FUNC(isSuper) |
| template<typename T > | |
| nint | isSub () const |
| template<typename T > | |
| nint | isSuper () const |
| template<typename T > | |
| T * | cast () |
| template<typename T > | |
| const T * | cast () const BY_CONST_FUNC(cast< T >()) virtual void *cast(const type &to) |
| Safe cast to target type using type hierarchy information | |
| const void * | cast (const type &to) const BY_CONST_FUNC(cast(to)) void *cast(const type *it) BY_SIDE_FUNC(cast) |
by::clonable(으)로부터 상속된 Public 멤버 함수 | |
| virtual me * | clone () const =0 |
| virtual me * | cloneDeep () const |
| virtual void | onCloneDeep (const me &from) |
Protected 멤버 함수 | |
| virtual ncnt | getArgCount () const |
| void | _delArgs (flagArgs &a, ncnt deleteOptionCnt) const |
Deletes arguments from the flagArgs list. | |
| virtual const strings & | _getRegExpr () const =0 |
| virtual res | _onTake (const flagArgs &tray, cli &c, interpreter &ip, starter &s, errReport &rpt) const =0 |
by::instance(으)로부터 상속된 Protected 멤버 함수 | |
| nbool | _setId (id new1) |
추가로 상속된 멤버들 | |
by::instance(으)로부터 상속된 정적 Public 멤버 함수 | |
| static vault & | getVault () |
by::instance(으)로부터 상속된 정적 Protected 멤버 함수 | |
| static instancer * | _getMgr () |
Base class for command-line flag handling
Handles flags commonly seen in shell-based programs. Note this class doesn't represent a flag like --version, but rather handles whether such flags exist and what actions to take.
Each flag defines not only its name but also a description of its functionality. These are used by helpFlag.
Each flag class has a defined pattern to search for. For example, verFlag searches for the --version string in program arguments. If found, it retrieves version info from buildFeature and outputs it. This behavior works by calling flag::take(), which uses the regex defined in each derived class's _getRegExpr() to find the desired pattern. Since regex is used, flag order is ignored.
Multiple patterns can be defined in regex:
Matches either ^\-S$ or ^\--show-structure$.
Consider verFlag: when --version exists in arguments, it outputs version. After operating, it removes --version from flagArgs to prevent verFlag from running again.
Now consider bufferSrcFlag, used like: --script "main() void: print(\"wow!\")"
Breaking this down: --script indicates flag start, followed by space and "<your code>" which is the frontend code body argument to execute. Some flags consume not just the matched pattern but additional arguments. Each derived flag class can override getArgCount() to specify how many additional arguments to extract.
bufferSrcFlag needs preliminary work before program start. Conversely, verFlag immediately outputs version and terminates without interpretation once matched (as most programs do). To terminate immediately after matching, override _onTake() to return EXIT_PROGRAM. For continued operation like bufferSrcFlag, return MATCH.
Deletes arguments from the flagArgs list.
This method is used internally to remove arguments that have been consumed by this flag, preventing them from being processed again by other flags.
| a | The flagArgs instance from which arguments are to be deleted. |
| deleteOptionCnt | a count indicating how much arguments to delete. |
| pattern | it's used to determine whether a pattern for a flag or not. it usually starts with one or two hyphens. |
when this flag matched to one of args, the value of returning this func will be count of continuous argument of this flag.
by::bufferSrcFlag에서 재구현되었습니다.
|
virtual |