fix8  version 1.4.0
Open Source C++ FIX Framework
consolemenu.hpp
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------------------
2 /*
3 
4 Fix8 is released under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
5 
6 Fix8 Open Source FIX Engine.
7 Copyright (C) 2010-16 David L. Dight <fix@fix8.org>
8 
9 Fix8 is free software: you can redistribute it and / or modify it under the terms of the
10 GNU Lesser General Public License as published by the Free Software Foundation, either
11 version 3 of the License, or (at your option) any later version.
12 
13 Fix8 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
14 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 You should have received a copy of the GNU Lesser General Public License along with Fix8.
17 If not, see <http://www.gnu.org/licenses/>.
18 
19 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO
20 THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
21 COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
22 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO
24 THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
25 YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
26 
27 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
28 HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED
29 ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
30 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
31 NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
32 THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
33 HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
34 
35 */
36 //-------------------------------------------------------------------------------------------------
37 #ifndef FIX8_CONSOLEMENU_HPP_
38 #define FIX8_CONSOLEMENU_HPP_
39 
40 //-------------------------------------------------------------------------------------------------
41 namespace FIX8 {
42 
43 //-------------------------------------------------------------------------------------------------
44 using MsgList = std::deque<FIX8::Message *>;
45 
46 //-------------------------------------------------------------------------------------------------
49 {
50  const F8MetaCntx& _ctx;
51  std::istream& _is;
52  std::ostream& _os;
53  int _lpp;
55 
56 public:
62  ConsoleMenu (const F8MetaCntx& ctx, std::istream& is=std::cin, std::ostream& os=std::cout, int lpp=20)
63  : _ctx(ctx), _is(is), _os(os), _lpp(lpp) {}
64 
66  virtual ~ConsoleMenu () {}
67 
68  F8API virtual const BaseMsgEntry *SelectMsg() const;
69  F8API virtual const FieldTable::Pair *SelectField(const Message *msg, int groupid = 0) const;
70  F8API virtual int SelectRealm(const unsigned short fnum, const RealmBase *rb) const;
71  F8API Message *SelectFromMsg(const MsgList& lst) const;
72  F8API virtual int CreateMsgs(tty_save_state& tty, MsgList& lst) const;
73  F8API int CreateMsgsFrom(tty_save_state& tty, MsgList& lst, const MsgList& from) const;
74  F8API Message *RemoveMsg(tty_save_state& tty, MsgList& lst) const;
75  F8API void EditMsg(tty_save_state& tty, const FieldTable::Pair *fld, Message *msg) const;
76  F8API virtual int EditMsgs(tty_save_state& tty, MsgList& lst) const;
77  F8API virtual int DeleteMsgs(tty_save_state& tty, MsgList& lst) const;
78  F8API virtual int DeleteAllMsgs(tty_save_state& tty, MsgList& lst) const;
79 
80  int get_lpp() const { return _lpp; }
81  void set_lpp(int lpp) { _lpp = lpp; }
82 
83  bool get_yn(const f8String& prompt, bool echo=false) const { return toupper(get_key(prompt, echo)) == 'Y'; }
84  char get_key(const f8String& prompt=std::string(), bool echo=false) const
85  {
86  char ch(0);
87  _is.clear();
88  if (!prompt.empty())
89  _os << prompt << std::flush;
90  _is.get(ch);
91  if (!_is.bad() && ch != 0x3 && ch != 0xa)
92  {
93  if (echo)
94  _os << ch;
95  return ch;
96  }
97  return 0;
98  }
100 };
101 
102 //-------------------------------------------------------------------------------------------------
103 
104 } // FIX8
105 
106 #endif // FIX8_CONSOLEMENU_HPP_
F8API f8String & GetString(tty_save_state &tty, f8String &to) const
virtual ~ConsoleMenu()
Dtor.
Definition: consolemenu.hpp:66
Message instantiation table entry.
Definition: message.hpp:192
Pair abstraction for use with GeneratedTable.
Definition: f8types.hpp:69
F8API Message * RemoveMsg(tty_save_state &tty, MsgList &lst) const
F8API int CreateMsgsFrom(tty_save_state &tty, MsgList &lst, const MsgList &from) const
std::ostream & _os
Definition: consolemenu.hpp:52
F8API void EditMsg(tty_save_state &tty, const FieldTable::Pair *fld, Message *msg) const
std::deque< FIX8::Message * > MsgList
Definition: consolemenu.hpp:44
virtual F8API int SelectRealm(const unsigned short fnum, const RealmBase *rb) const
Domain range/set static metadata base class.
Definition: field.hpp:58
virtual F8API int EditMsgs(tty_save_state &tty, MsgList &lst) const
static const f8String _fld_prompt
Definition: consolemenu.hpp:54
const F8MetaCntx & ctx()
Compiler generated metadata object, accessed through this function.
#define F8API
Definition: f8dll.h:60
Console test harness menu.
Definition: consolemenu.hpp:48
const F8MetaCntx & _ctx
Definition: consolemenu.hpp:50
A complete Fix message with header, body and trailer.
Definition: message.hpp:1058
std::istream & _is
Definition: consolemenu.hpp:51
F8API Message * SelectFromMsg(const MsgList &lst) const
virtual F8API int CreateMsgs(tty_save_state &tty, MsgList &lst) const
char get_key(const f8String &prompt=std::string(), bool echo=false) const
Definition: consolemenu.hpp:84
void set_lpp(int lpp)
Definition: consolemenu.hpp:81
ConsoleMenu(const F8MetaCntx &ctx, std::istream &is=std::cin, std::ostream &os=std::cout, int lpp=20)
Definition: consolemenu.hpp:62
bool get_yn(const f8String &prompt, bool echo=false) const
Definition: consolemenu.hpp:83
virtual F8API const FieldTable::Pair * SelectField(const Message *msg, int groupid=0) const
virtual F8API int DeleteAllMsgs(tty_save_state &tty, MsgList &lst) const
int get_lpp() const
Definition: consolemenu.hpp:80
Static metadata context class - one per FIX xml schema.
Definition: message.hpp:210
virtual F8API const BaseMsgEntry * SelectMsg() const
Definition: consolemenu.cpp:50
static const f8String _opt_keys
Definition: consolemenu.hpp:54
std::string f8String
Definition: f8types.hpp:47
virtual F8API int DeleteMsgs(tty_save_state &tty, MsgList &lst) const