2003-09-09 18:27:24 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-17 11:28:23 +00:00
|
|
|
/**
|
2003-09-09 18:27:24 +00:00
|
|
|
* \file BranchList.h
|
2003-08-17 11:28:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
* \author Martin Vermeer
|
2003-09-09 18:27:24 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-08-17 11:28:23 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* \class Branch
|
|
|
|
*
|
|
|
|
* A class describing a 'branch', i.e., a named alternative for
|
|
|
|
* selectively outputting some parts of a document while suppressing
|
|
|
|
* other parts.
|
|
|
|
*
|
|
|
|
* A branch has a name, can either be selected or not, and uses a
|
|
|
|
* user-specifyable background colour. All these can be set and
|
|
|
|
* queried.
|
2003-09-09 18:27:24 +00:00
|
|
|
*
|
2003-08-17 11:28:23 +00:00
|
|
|
* \class BranchList
|
|
|
|
*
|
|
|
|
* A class containing a vector of all defined branches within a
|
|
|
|
* document. Has methods for selecting or deselecting branches by
|
|
|
|
* name, for outputting a '|'-separated string of all elements or only
|
|
|
|
* the selected ones, and for adding and removing elements.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef BRANCHES_H
|
|
|
|
#define BRANCHES_H
|
|
|
|
|
2006-03-23 20:04:05 +00:00
|
|
|
#include "Color.h"
|
|
|
|
|
2006-11-03 15:16:45 +00:00
|
|
|
#include "support/docstring.h"
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
#include <list>
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
class Branch {
|
|
|
|
public:
|
2006-03-23 20:04:05 +00:00
|
|
|
///
|
|
|
|
Branch();
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring const & getBranch() const;
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2006-11-03 15:16:45 +00:00
|
|
|
void setBranch(docstring const &);
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
|
|
|
bool getSelected() const;
|
2003-12-14 16:33:56 +00:00
|
|
|
/** Select/deselect the branch.
|
|
|
|
* \return true if the selection status changes.
|
|
|
|
*/
|
|
|
|
bool setSelected(bool);
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
RGBColor const & getColor() const;
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
void setColor(RGBColor const &);
|
2006-03-23 20:04:05 +00:00
|
|
|
/**
|
|
|
|
* Set color from a string "#rrggbb".
|
|
|
|
* Use LColor: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 LColor:background.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
void setColor(std::string const &);
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring branch_;
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
|
|
|
bool selected_;
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
RGBColor color_;
|
2003-08-17 11:28:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BranchList {
|
|
|
|
///
|
|
|
|
typedef std::list<Branch> List;
|
2003-12-14 16:33:56 +00:00
|
|
|
public:
|
|
|
|
typedef List::const_iterator const_iterator;
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
|
|
///
|
2006-11-03 15:16:45 +00:00
|
|
|
BranchList() : separator_(from_ascii("|")) {}
|
2003-12-14 16:33:56 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2005-11-02 11:27:08 +00:00
|
|
|
bool empty() const { return list.empty(); }
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2005-04-26 11:12:20 +00:00
|
|
|
void clear() { list.clear(); }
|
2005-03-27 13:31:04 +00:00
|
|
|
///
|
2003-12-14 16:33:56 +00:00
|
|
|
const_iterator begin() const { return list.begin(); }
|
|
|
|
const_iterator end() const { return list.end(); }
|
|
|
|
|
|
|
|
/** \returns the Branch with \c name. If not found, returns 0.
|
|
|
|
*/
|
2006-11-03 15:16:45 +00:00
|
|
|
Branch * find(docstring const & name);
|
|
|
|
Branch const * find(docstring const & name) const;
|
2003-12-14 16:33:56 +00:00
|
|
|
|
|
|
|
/** Add (possibly multiple (separated by separator())) branches to list
|
|
|
|
* \returns true if a branch is added.
|
|
|
|
*/
|
2006-11-03 15:16:45 +00:00
|
|
|
bool add(docstring const &);
|
2003-12-14 16:33:56 +00:00
|
|
|
/** remove a branch from list by name
|
|
|
|
* \returns true if a branch is removed.
|
|
|
|
*/
|
2006-11-03 15:16:45 +00:00
|
|
|
bool remove(docstring const &);
|
2003-09-09 18:27:24 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
List list;
|
|
|
|
///
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring separator_;
|
2003-08-17 11:28:23 +00:00
|
|
|
};
|
|
|
|
|
2004-01-05 17:33:57 +00:00
|
|
|
|
|
|
|
class BranchNamesEqual : public std::unary_function<Branch, bool> {
|
|
|
|
public:
|
2006-11-03 15:16:45 +00:00
|
|
|
BranchNamesEqual(docstring const & name)
|
2004-01-05 17:33:57 +00:00
|
|
|
: name_(name) {}
|
|
|
|
bool operator()(Branch const & branch) const
|
|
|
|
{
|
|
|
|
return branch.getBranch() == name_;
|
|
|
|
}
|
|
|
|
private:
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring name_;
|
2004-01-05 17:33:57 +00:00
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
#endif
|