File: IndicesList.h

package info (click to toggle)
lyx 2.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 121,196 kB
  • sloc: cpp: 405,401; ansic: 106,819; python: 27,007; sh: 6,826; makefile: 5,497; pascal: 2,055; perl: 1,523; objc: 1,025; tcl: 163; xml: 153; sed: 16
file content (129 lines) | stat: -rw-r--r-- 2,922 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// -*- C++ -*-
/**
 * \file IndicesList.h
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author Jürgen Spitzmüller
 *
 * Full author contact details are available in file CREDITS.
 */

#ifndef INDICESLIST_H
#define INDICESLIST_H

#include "ColorCode.h"

#include "support/docstring.h"

#include <list>


namespace lyx {

/**
 * \class Index
 *
 * A class describing an Index type, such as "Index of Names".
 * Different Index types are used in split Indices
 *
 * An Index has a name and a shortcut notation. It uses a
 * user-specifiable GUI colour. All these can be set and
 * queried.
 *
 * \class IndicesList
 *
 * A class containing a vector of all defined indices within a
 * document. It has methods for outputting a '|'-separated string
 * of all elements, and for adding, removing and renaming elements.
 */

class Index {
public:
	///
	Index();
	///
	docstring const & index() const;
	///
	void setIndex(docstring const &);
	///
	docstring const & shortcut() const;
	///
	void setShortcut(docstring const &);
	///
	RGBColor const & color() const;
	///
	void setColor(RGBColor const &);
	/**
	 * Set color from a string "#rrggbb".
	 * Use Color:background if the string is no valid color.
	 * This ensures compatibility with LyX 1.4.0 that had the symbolic
	 * color "none" that was displayed as Color:background.
	 */
	void setColor(std::string const &);

private:
	///
	docstring index_;
	///
	docstring shortcut_;
	///
	RGBColor color_;
};


class IndicesList {
	///
	typedef std::list<Index> List;
public:
	typedef List::const_iterator const_iterator;

	///
	IndicesList() : separator_(from_ascii("|")) {}

	///
	bool empty() const { return list.empty(); }
	///
	void clear() { list.clear(); }
	///
	const_iterator begin() const { return list.begin(); }
	const_iterator end() const { return list.end(); }

	/** \returns the Index with \c name. If not found, returns 0.
	 */
	Index * find(docstring const & name);
	Index const * find(docstring const & name) const;

	/** \returns the Index with the shortcut \c shortcut.
	 *  If not found, returns 0.
	 */
	Index * findShortcut(docstring const & shortcut);
	Index const * findShortcut(docstring const & shortcut) const;

	/** Add (possibly multiple (separated by separator())) indices to list
	 *  \returns true if an index is added.
	 */
	bool add(docstring const & n, docstring const & s = docstring());
	/** Add the default index (if not already there)
	 *  \returns true if an index is added.
	 */
	bool addDefault(docstring const & n);
	/** remove an index from list by name
	 *  \returns true if an index is removed.
	 */
	bool remove(docstring const &);
	/** rename an index in list
	 *  \returns true if renaming succeeded.
	 */
	bool rename(docstring const &, docstring const &);

private:
	///
	List list;
	///
	docstring separator_;
};

} // namespace lyx

#endif // INDICESLIST_H