CLI  2.9
ui_yesno.cpp
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
28 #include "cli/pch.h"
29 
30 #include "cli/ui_yesno.h"
31 #include "cli/shell.h"
32 
33 
35 
36  CLI_NS_BEGIN(ui)
37 
38 
39  static const tk::Queue<ResourceString>& GetYesNoChoice(void)
41  {
42  static tk::Queue<ResourceString> tk_YesNo(2);
43  if (tk_YesNo.IsEmpty())
44  {
45  tk_YesNo.AddTail(ResourceString()
46  .SetString(ResourceString::LANG_EN, "Yes")
47  .SetString(ResourceString::LANG_FR, "Oui")
48  );
49  tk_YesNo.AddTail(ResourceString()
50  .SetString(ResourceString::LANG_EN, "No")
51  .SetString(ResourceString::LANG_FR, "Non")
52  );
53  }
54  return tk_YesNo;
55  }
56 
57 
58  YesNo::YesNo(const bool B_DefaultAnswer)
59  : Choice(B_DefaultAnswer ? 0 : 1, GetYesNoChoice())
60  {
61  }
62 
63  YesNo::YesNo(ExecutionContext& CLI_ParentContext, const bool B_DefaultAnswer)
64  : Choice(CLI_ParentContext, B_DefaultAnswer ? 0 : 1, GetYesNoChoice())
65  {
66  }
67 
69  {
70  }
71 
72  const bool YesNo::GetYesNo(void) const
73  {
74  if (Choice::GetChoice() == 0)
75  {
76  return true;
77  }
78  else
79  {
80  return false;
81  }
82  }
83 
84  void YesNo::OnKey(const KEY E_KeyCode)
85  {
86  Choice::OnKey(E_KeyCode);
87  }
88 
89  CLI_NS_END(ui)
90 
92 
Main namespace of the CLI library.
Shell class definition.
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
ResourceString class.
virtual void OnKey(const KEY E_KeyCode)
Handler called on character input.
Definition: ui_yesno.cpp:84
Execution context.
Definition: exec_context.h:149
CLI library default pre-compiled header.
Choice user interface class.
Definition: ui_choice.h:43
YesNo(const bool B_DefaultAnswer)
Top execution context constructor.
Definition: ui_yesno.cpp:58
enum _KEY KEY
Input keys.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
virtual ~YesNo(void)
Destructor.
Definition: ui_yesno.cpp:68
virtual void OnKey(const KEY E_KeyCode)
Handler called on character input.
Definition: ui_choice.cpp:142
const int GetChoice(void) const
Choice retrieval.
Definition: ui_choice.cpp:85
YesNo class definition.
const bool GetYesNo(void) const
Yes/No answer retrieval.
Definition: ui_yesno.cpp:72