]> git.lyx.org Git - lyx.git/blob - src/funcrequest.C
Change to use preffered calling of Boost.Function
[lyx.git] / src / funcrequest.C
1 /**
2  * \file funcrequest.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "funcrequest.h"
14
15 #include <iostream>
16 #include <sstream>
17 #include <vector>
18
19 using std::getline;
20
21 using std::istringstream;
22 using std::vector;
23 using std::string;
24
25
26 FuncRequest::FuncRequest()
27         : action(LFUN_NOACTION), x(0), y(0), button_(mouse_button::none)
28 {}
29
30
31 FuncRequest::FuncRequest(kb_action act)
32         : action(act), x(0), y(0), button_(mouse_button::none)
33 {}
34
35
36 FuncRequest::FuncRequest(kb_action act, string const & arg)
37         : action(act), argument(arg), x(0), y(0), button_(mouse_button::none)
38 {}
39
40
41 FuncRequest::FuncRequest(kb_action act, int ax, int ay, mouse_button::state but)
42         : action(act), x(ax), y(ay), button_(but)
43 {}
44
45
46 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg)
47         : action(cmd.action), argument(arg),
48           x(cmd.x), y(cmd.y), button_(cmd.button_)
49 {}
50
51
52 mouse_button::state FuncRequest::button() const
53 {
54         return button_;
55 }
56
57
58 void split(vector<string> & args, string str)
59 {
60         istringstream is(str);
61         while (is) {
62                 char c;
63                 string s;
64                 is >> c;
65                 if (c == '"')
66                         getline(is, s, '"');
67                 else {
68                         is.putback(c);
69                         is >> s;
70                 }
71                 args.push_back(s);
72         }
73 }
74
75
76 string FuncRequest::getArg(unsigned int i) const
77 {
78         vector<string> args;
79         split(args, argument);
80         return i < args.size() ? args[i] : string();
81 }
82
83
84 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
85 {
86         return lhs.action == rhs.action && lhs.argument == rhs.argument;
87 }
88
89
90 std::ostream & operator<<(std::ostream & os, FuncRequest const & cmd)
91 {
92         return os
93                 << " action: " << cmd.action
94                 << " arg: '" << cmd.argument << "'"
95                 << " x: " << cmd.x
96                 << " y: " << cmd.y;
97 }