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"
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <string>
|
2003-08-17 11:28:23 +00:00
|
|
|
#include <list>
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
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
|
|
|
///
|
2003-12-14 16:33:56 +00:00
|
|
|
std::string const & getBranch() const;
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void setBranch(std::string 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-03-23 20:04:05 +00:00
|
|
|
lyx::RGBColor const & getColor() const;
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
2006-03-23 20:04:05 +00:00
|
|
|
void setColor(lyx::RGBColor const &);
|
|
|
|
/**
|
|
|
|
* 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:
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string branch_;
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
|
|
|
bool selected_;
|
|
|
|
///
|
2006-03-23 20:04:05 +00:00
|
|
|
lyx::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
|
|
|
|
|
|
|
///
|
2003-12-14 16:33:56 +00:00
|
|
|
BranchList() : separator_("|") {}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
Branch * find(std::string const & name);
|
|
|
|
Branch const * find(std::string const & name) const;
|
|
|
|
|
|
|
|
/** Add (possibly multiple (separated by separator())) branches to list
|
|
|
|
* \returns true if a branch is added.
|
|
|
|
*/
|
|
|
|
bool add(std::string const &);
|
|
|
|
/** remove a branch from list by name
|
|
|
|
* \returns true if a branch is removed.
|
|
|
|
*/
|
|
|
|
bool remove(std::string const &);
|
2003-09-09 18:27:24 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
List list;
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string 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:
|
|
|
|
BranchNamesEqual(std::string const & name)
|
|
|
|
: name_(name) {}
|
|
|
|
bool operator()(Branch const & branch) const
|
|
|
|
{
|
|
|
|
return branch.getBranch() == name_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::string name_;
|
|
|
|
};
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
#endif
|