]> git.lyx.org Git - lyx.git/blob - src/insets/InsetListingsParams.h
6341bb994e35071a84a3125c52dfac70444415a9
[lyx.git] / src / insets / InsetListingsParams.h
1 // -*- C++ -*-
2 /**
3  * \file InsetListingsParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Bo Peng
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETLISTINGSPARAMS_H
13 #define INSETLISTINGSPARAMS_H
14
15 #include <map>
16 #include <exception>
17 #include "Lexer.h"
18 #include "InsetCollapsable.h"
19
20 namespace lyx {
21
22 class InsetListingsParams {
23 public:
24         ///
25         InsetListingsParams();
26
27         ///
28         InsetListingsParams(std::string const &, bool in=false,
29                 InsetCollapsable::CollapseStatus s = InsetCollapsable::Open);
30
31         /// write parameters to an ostream
32         void write(std::ostream &) const;
33
34         /// read parameters from an ostream
35         void read(Lexer &);
36
37         /// valid parameter string
38         /// \param valid_key whether or not strip leading @, which is 
39         ///                  used to bypass validator
40         std::string params(std::string const & sep=",", bool valid_key=false) const;
41
42         /// add key=value to params_
43         void addParam(std::string const & key, std::string const & value);
44
45         /// add a few parameters
46         void addParams(std::string const & par);
47
48         /// set params_ with par, throw an exception if par is valid
49         void setParams(std::string const & par);
50
51         /// generate a parameter string that can be safely save and restored
52         /// by lyx' lexer
53         std::string encodedString() const;
54
55         /// newline (\n) separated parameters. comma can be removed.
56         /// One possible complication is that , may appear in option value.
57         std::string separatedParams(bool keepComma = false) const;
58
59         /// get parameter from encoded string
60         void fromEncodedString(std::string const & par);
61
62         ///
63         bool isInline() const { return inline_; }
64
65         ///
66         bool isFloat() const;
67
68         ///
69         InsetCollapsable::CollapseStatus status() const { return status_; }
70
71         ///
72         void setInline(bool i) { inline_ = i; }
73
74         /// get value of option \c param
75         std::string getParamValue(std::string const & param) const;
76
77         ///
78         void clear() { params_.clear(); }
79
80 private:
81         /// inline or normal listings
82         bool inline_;
83
84         /// key-value pairs of the parameters
85         std::map<std::string, std::string> params_;
86
87         /// collapsable status
88         InsetCollapsable::CollapseStatus status_;
89 };
90
91
92 class invalidParam : public std::exception {
93 public:
94         invalidParam(docstring const & details)
95                                         : details_(to_utf8(details))
96         {}
97
98         virtual const char * what() const throw() {
99                 return details_.c_str();
100         }
101
102         virtual ~invalidParam() throw() {}
103 private:
104         std::string const details_;
105 };
106
107
108 } // namespace lyx
109
110 #endif