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
|
|
|
|
|
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:
|
|
|
|
///
|
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
|
|
|
///
|
2003-12-14 16:33:56 +00:00
|
|
|
std::string const & getColor() const;
|
2003-08-17 11:28:23 +00:00
|
|
|
///
|
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_;
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string 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
|
|
|
///
|
2003-08-18 12:27:49 +00:00
|
|
|
bool empty() { return list.empty(); }
|
2003-08-17 11:28:23 +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
|