blob: 0c502cc364b47532440b810d8bfab9e100388fd3 [file] [log] [blame]
Greg Claytoneffe5c92011-05-03 22:09:39 +00001//===-- OptionGroupBoolean.cpp ----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Johnny Chen4bee32e2011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupBoolean.h"
Greg Claytoneffe5c92011-05-03 22:09:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16
17using namespace lldb;
18using namespace lldb_private;
19
20OptionGroupBoolean::OptionGroupBoolean (uint32_t usage_mask,
21 bool required,
22 const char *long_option,
Greg Clayton3bcdfc02012-12-04 00:32:51 +000023 int short_option,
Greg Claytoneffe5c92011-05-03 22:09:39 +000024 const char *usage_text,
Greg Claytonb5f0fea2012-09-27 22:26:11 +000025 bool default_value,
26 bool no_argument_toggle_default) :
Greg Claytoneffe5c92011-05-03 22:09:39 +000027 m_value (default_value, default_value)
28{
29 m_option_definition.usage_mask = usage_mask;
30 m_option_definition.required = required;
31 m_option_definition.long_option = long_option;
32 m_option_definition.short_option = short_option;
Zachary Turnerdf734cd2014-07-09 16:32:07 +000033 m_option_definition.validator = nullptr;
Virgile Belloe2607b52013-09-05 16:42:23 +000034 m_option_definition.option_has_arg = no_argument_toggle_default ? OptionParser::eNoArgument : OptionParser::eRequiredArgument;
Ed Masted78c9572014-04-20 00:31:37 +000035 m_option_definition.enum_values = nullptr;
Greg Claytonb5f0fea2012-09-27 22:26:11 +000036 m_option_definition.completion_type = 0;
37 m_option_definition.argument_type = eArgTypeBoolean;
Greg Claytoneffe5c92011-05-03 22:09:39 +000038 m_option_definition.usage_text = usage_text;
39}
40
41OptionGroupBoolean::~OptionGroupBoolean ()
42{
43}
44
45Error
46OptionGroupBoolean::SetOptionValue (CommandInterpreter &interpreter,
47 uint32_t option_idx,
48 const char *option_arg)
49{
Greg Claytonb5f0fea2012-09-27 22:26:11 +000050 Error error;
Virgile Belloe2607b52013-09-05 16:42:23 +000051 if (m_option_definition.option_has_arg == OptionParser::eNoArgument)
Greg Claytonb5f0fea2012-09-27 22:26:11 +000052 {
53 // Not argument, toggle the default value and mark the option as having been set
54 m_value.SetCurrentValue (!m_value.GetDefaultValue());
55 m_value.SetOptionWasSet ();
56 }
57 else
58 {
59 error = m_value.SetValueFromCString (option_arg);
60 }
Greg Claytoneffe5c92011-05-03 22:09:39 +000061 return error;
62}
63
64void
65OptionGroupBoolean::OptionParsingStarting (CommandInterpreter &interpreter)
66{
67 m_value.Clear();
68}