2015-02-18 23:25:25 +08:00
|
|
|
//===-- CMICmdArgValBase.h --------------------------------------*- C++ -*-===//
|
2014-05-16 18:51:01 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// In-house headers:
|
|
|
|
#include "MIUtilString.h"
|
|
|
|
#include "MICmdArgSet.h"
|
|
|
|
|
|
|
|
//++ ============================================================================
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: MI common code class. Command argument base class. Arguments objects
|
|
|
|
// needing specialization derived from *this class. An argument knows
|
|
|
|
// what type of argument it is and how it is to interpret the options
|
|
|
|
// (context) string to find and validate a matching argument and so
|
|
|
|
// extract a value from it.
|
|
|
|
// Argument objects are added to the CMICmdArgSet container object.
|
|
|
|
// Once added the container they belong to that contain and will be
|
|
|
|
// deleted when the container goes out of scope. Allocate argument
|
|
|
|
// objects on the heap and pass in to the Add().
|
|
|
|
// Note the code is written such that a command will produce an error
|
|
|
|
// should it be presented with arguments or options it does not understand.
|
|
|
|
// A command can recognise an option or argument then ignore if it
|
|
|
|
// wishes (a warning is sent to the MI's Log file). This is so it is
|
|
|
|
// hardwired to fail and catch arguments or options that presented by
|
|
|
|
// different driver clients.
|
|
|
|
// Based on the Interpreter pattern.
|
|
|
|
// Gotchas: None.
|
|
|
|
// Authors: Illya Rudkin 14/04/2014.
|
|
|
|
// Changes: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
|
|
|
class CMICmdArgValBase : public CMICmdArgSet::IArg
|
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
// Methods:
|
|
|
|
public:
|
|
|
|
/* ctor */ CMICmdArgValBase(void);
|
|
|
|
/* ctor */ CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2014-11-18 02:06:21 +08:00
|
|
|
// Overrideable:
|
|
|
|
public:
|
|
|
|
/* dtor */ virtual ~CMICmdArgValBase(void);
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2014-11-18 02:06:21 +08:00
|
|
|
// Overridden:
|
|
|
|
public:
|
|
|
|
// From CMICmdArgSet::IArg
|
|
|
|
virtual bool GetFound(void) const;
|
|
|
|
virtual bool GetIsHandledByCmd(void) const;
|
|
|
|
virtual bool GetIsMandatory(void) const;
|
|
|
|
virtual bool GetIsMissingOptions(void) const;
|
|
|
|
virtual const CMIUtilString &GetName(void) const;
|
|
|
|
virtual bool GetValid(void) const;
|
|
|
|
virtual bool Validate(CMICmdArgContext &vwArgContext);
|
|
|
|
|
|
|
|
// Attributes:
|
|
|
|
protected:
|
|
|
|
bool m_bFound; // True = yes found in arguments options text, false = not found
|
|
|
|
bool m_bValid; // True = yes argument parsed and valid, false = not valid
|
|
|
|
bool m_bMandatory; // True = yes arg must be present, false = optional argument
|
|
|
|
CMIUtilString m_strArgName;
|
|
|
|
bool m_bHandled; // True = Command processes *this option, false = not handled
|
|
|
|
bool m_bIsMissingOptions; // True = Command needs more information, false = ok
|
2014-05-16 18:51:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//++ ============================================================================
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: MI common code class. Templated command argument base class.
|
|
|
|
// Gotchas: None.
|
|
|
|
// Authors: Illya Rudkin 14/04/2014.
|
|
|
|
// Changes: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
// Methods:
|
|
|
|
public:
|
|
|
|
/* ctor */ CMICmdArgValBaseTemplate(void);
|
|
|
|
/* ctor */ CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
|
|
|
|
//
|
|
|
|
const T &GetValue(void) const;
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2014-11-18 02:06:21 +08:00
|
|
|
// Overrideable:
|
|
|
|
public:
|
|
|
|
/* dtor */ virtual ~CMICmdArgValBaseTemplate(void);
|
2014-05-16 18:51:01 +08:00
|
|
|
|
2014-11-18 02:06:21 +08:00
|
|
|
// Attributes:
|
|
|
|
protected:
|
|
|
|
T m_argValue;
|
2014-05-16 18:51:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMICmdArgValBaseTemplate constructor.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
template <class T> CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(void)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMICmdArgValBaseTemplate constructor.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: vrArgName - (R) Argument's name to search by.
|
|
|
|
// vbMandatory - (R) True = Yes must be present, false = optional argument.
|
|
|
|
// vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
template <class T>
|
|
|
|
CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
|
|
|
|
: CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: CMICmdArgValBaseTemplate destructor.
|
|
|
|
// Type: Overrideable.
|
|
|
|
// Args: None.
|
|
|
|
// Return: None.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
template <class T> CMICmdArgValBaseTemplate<T>::~CMICmdArgValBaseTemplate(void)
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//++ ------------------------------------------------------------------------------------
|
2014-11-18 02:06:21 +08:00
|
|
|
// Details: Retrieve the value the argument parsed from the command's argument / options
|
|
|
|
// text string.
|
|
|
|
// Type: Method.
|
|
|
|
// Args: None.
|
|
|
|
// Return: Template type & - The arg value of *this object.
|
|
|
|
// Throws: None.
|
2014-05-16 18:51:01 +08:00
|
|
|
//--
|
2014-11-18 02:06:21 +08:00
|
|
|
template <class T>
|
|
|
|
const T &
|
|
|
|
CMICmdArgValBaseTemplate<T>::GetValue(void) const
|
2014-05-16 18:51:01 +08:00
|
|
|
{
|
2014-11-18 02:06:21 +08:00
|
|
|
return m_argValue;
|
2014-05-16 18:51:01 +08:00
|
|
|
}
|