Attached. Martin V
-- Martin Vermeer [EMAIL PROTECTED] Helsinki University of Technology Dept. of Surveying, Inst. of Geodesy P.O. Box 1200, FIN-02015 HUT, Finland :wq
// -*- C++ -*- /* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team. * * * ====================================================== */ /** * \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. * * \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 #include "LString.h" #include "LColor.h" #include <vector> class Branch { public: /// string getBranch() const; /// void setBranch(string const &); /// bool getSelected() const; /// void setSelected(bool); /// LColor::color getColor() const; /// void setColor(LColor::color const &); private: /// string branch_; /// bool selected_; /// LColor::color color_; }; class BranchList { public: /// typedef std::vector<Branch> List; /// void select(string const &); /// void deselect(string const &); /// void add(string const &); /// void remove(string const &); /// bool selected(string const &); /// string allBranches(); /// string allSelected(); private: /// List list; }; #endif
/* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team. * * * ====================================================== */ #include "BranchList.h" using std::vector; string Branch::getBranch() const { return branch_; } void Branch::setBranch(string const & s) { branch_ = s; } bool Branch::getSelected() const { return selected_; } void Branch::setSelected(bool b) { selected_ = b; } LColor::color Branch::getColor() const { return color_; } void Branch::setColor(LColor::color const & c) { color_ = c; } void BranchList::select(string const & s) { List::iterator it = list.begin(); List::iterator end = list.end(); for (; it != end; it++) { if (s.find(it->getBranch(), 0) != string::npos) it->setSelected(true); } } void BranchList::deselect(string const & s) { List::iterator it = list.begin(); List::iterator end = list.end(); for (; it != end; it++) { if (s.find(it->getBranch(), 0) != string::npos) it->setSelected(false); } } void BranchList::add(string const & s) { Branch br; br.setBranch(s); br.setSelected(false); br.setColor(LColor::none); list.push_back(); } void BranchList::remove(string const & s) { List::iterator it = list.begin(); List::iterator end = list.end(); for (; it != end; it++) { if (it->getBranch() == s) list.erase(it); } } bool BranchList::selected(string const & s) { List::iterator it = list.begin(); List::iterator end = list.end(); for (; it != end; it++) { if (s == it->getBranch()) return true; } return false; } string BranchList::allBranches() { List::iterator it = list.begin(); List::iterator end = list.end(); string ret; string ch = "|"; for (; it != end; it++) { ret += it->getBranch() + ch; } // remove final '|': unsigned i = ret.find_last_of(ch); if (i != string::npos) ret.erase(i); return ret; } string BranchList::allSelected() { List::iterator it = list.begin(); List::iterator end = list.end(); string ret; string ch = "|"; for (; it != end; it++) { if (it->getSelected()) ret += it->getBranch() + ch; } // remove final '|': unsigned i = ret.find_last_of(ch); if (i != string::npos) ret.erase(i); return ret; }
pgp00000.pgp
Description: PGP signature