Another minor change, but this should almost get us to the point that we
[lyx.git] / src / BranchList.h
blob21f8d05303d6b4fd86791bbdbe4ea58c14d2613e
1 // -*- C++ -*-
2 /**
3 * \file BranchList.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
6 * \author Martin Vermeer
8 * Full author contact details are available in file CREDITS.
11 * \class Branch
13 * A class describing a 'branch', i.e., a named alternative for
14 * selectively outputting some parts of a document while suppressing
15 * other parts.
17 * A branch has a name, can either be selected or not, and uses a
18 * user-specifyable background colour. All these can be set and
19 * queried.
21 * \class BranchList
23 * A class containing a vector of all defined branches within a
24 * document. Has methods for selecting or deselecting branches by
25 * name, for outputting a '|'-separated string of all elements or only
26 * the selected ones, and for adding and removing elements.
30 #ifndef BRANCHLIST_H
31 #define BRANCHLIST_H
33 #include "ColorCode.h"
35 #include "support/docstring.h"
37 #include <list>
40 namespace lyx {
42 class Branch {
43 public:
44 ///
45 Branch();
46 ///
47 docstring const & branch() const;
48 ///
49 void setBranch(docstring const &);
50 ///
51 bool isSelected() const;
52 /** Select/deselect the branch.
53 * \return true if the selection status changes.
55 bool setSelected(bool);
56 /** If true, the branch name will be appended
57 * to the output file name.
59 bool hasFilenameSuffix() const;
60 /// Select/deselect filename suffix property.
61 void setFilenameSuffix(bool);
62 ///
63 RGBColor const & color() const;
64 ///
65 void setColor(RGBColor const &);
66 /**
67 * Set color from a string "#rrggbb".
68 * Use Color:background if the string is no valid color.
69 * This ensures compatibility with LyX 1.4.0 that had the symbolic
70 * color "none" that was displayed as Color:background.
72 void setColor(std::string const &);
74 private:
75 ///
76 docstring branch_;
77 ///
78 bool selected_;
79 ///
80 bool filenameSuffix_;
81 ///
82 RGBColor color_;
86 class BranchList {
87 ///
88 typedef std::list<Branch> List;
89 public:
90 typedef List::const_iterator const_iterator;
92 ///
93 BranchList() : separator_(from_ascii("|")) {}
95 ///
96 bool empty() const { return list.empty(); }
97 ///
98 void clear() { list.clear(); }
99 ///
100 const_iterator begin() const { return list.begin(); }
101 const_iterator end() const { return list.end(); }
103 /** \returns the Branch with \c name. If not found, returns 0.
105 Branch * find(docstring const & name);
106 Branch const * find(docstring const & name) const;
108 /** Add (possibly multiple (separated by separator())) branches to list
109 * \returns true if a branch is added.
111 bool add(docstring const &);
112 /** remove a branch from list by name
113 * \returns true if a branch is removed.
115 bool remove(docstring const &);
116 /** rename an branch in list
117 * \returns true if renaming succeeded.
118 * if \p merge is true, the branch will be removed
119 * if a branch with the newname already exists.
121 bool rename(docstring const &, docstring const &, bool const merge = false);
122 /// get the complete filename suffix
123 docstring getFilenameSuffix() const;
125 private:
127 List list;
129 docstring separator_;
132 } // namespace lyx
134 #endif // BRANCHLIST_H