Get rid of ShareContainer.h

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9007 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2004-09-26 08:24:08 +00:00
parent 48e9df18b2
commit e0a50d3fb8
5 changed files with 25 additions and 104 deletions

View File

@ -1,11 +1,19 @@
2004-09-26 Lars Gullik Bjonnes <larsbj@gullik.net>
* Makefile.am (lyx_SOURCES): remove ShareContainer.h
* paragraph_pimpl.h: remove usage of ShareContainer
* paragraph_pimpl.C: remove initialization of ShareContainer.
2004-09-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
Fix bug #1666
* BufferView.C (putSelectionAt): change the semantics when
backwards == true: now, this just swaps cursor and anchor wrt the
forward case
* BufferView.h (putSelectionAt): add some documentation
* lyxfind.C (findBackwards): rewrite using while(). In particular,

View File

@ -101,7 +101,6 @@ lyx_SOURCES = \
PrinterParams.C \
PrinterParams.h \
RowList_fwd.h \
ShareContainer.h \
Spacing.C \
Spacing.h \
Thesaurus.C \

View File

@ -1,95 +0,0 @@
// -*- C++ -*-
/**
* \file ShareContainer.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
*
* Full author contact details are available in file CREDITS.
*/
#ifndef SHARECONTAINER_H
#define SHARECONTAINER_H
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <algorithm>
#include <functional>
/// Share objects between several users.
/**
This class can be used to reduce memory consuption when you have a lot
of equal objects used all over your code.
\author Lars Gullik Bjønnes
*/
template<class Share>
class ShareContainer : boost::noncopyable {
public:
///
typedef std::vector<boost::shared_ptr<Share> > Params;
///
typedef typename Params::value_type value_type;
/// Return a shared_ptr that points to a element equal to ps.
value_type
get(Share const & ps) const {
// First see if we already have this ps in the container
typename Params::iterator it = std::find_if(params.begin(),
params.end(),
isEqual(ps));
value_type tmp;
if (it == params.end()) {
// ok we don't have it so we should
// insert it.
tmp.reset(new Share(ps));
params.push_back(tmp);
// We clean here. This can cause us to have
// some (one) unique elemements some times
// but we should gain a lot in speed.
clean();
} else {
// yes we have it already
tmp = *it;
// move it forward - optimization
// makes the next find faster.
if (it != params.begin())
std::swap(*it, *(it - 1));
}
return tmp;
}
private:
/// A functor returning true if the elements are equal.
struct isEqual : public std::unary_function<value_type, bool> {
isEqual(Share const & s) : p_(s) {}
bool operator()(value_type const & p1) const {
return *p1.get() == p_;
}
private:
Share const & p_;
};
/// A functor returning true if the element is unique.
struct isUnique : public std::unary_function<value_type, bool> {
bool operator()(value_type const & p) const {
return p.unique();
}
};
/** Remove all unique items.
This removes all elements from params that is only referenced
from the private container. This can be considered a memory
optimizaton.
*/
void clean() const {
typename Params::iterator it = std::remove_if(params.begin(),
params.end(),
isUnique());
params.erase(it, params.end());
}
/// The actual container.
mutable Params params;
};
#endif

View File

@ -26,6 +26,7 @@
#include "outputparams.h"
#include "texrow.h"
#include <boost/next_prior.hpp>
using lyx::pos_type;
@ -36,8 +37,6 @@ using std::string;
using std::ostream;
// Initialize static member.
ShareContainer<LyXFont> Paragraph::Pimpl::FontTable::container;
// Initialization of the counter for the paragraph id's,
unsigned int Paragraph::Pimpl::paragraph_id = 0;
@ -666,7 +665,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
column += 17;
break;
case '*': case '[':
case '*': case '[':
// avoid being mistaken for optional arguments
os << '{' << c << '}';
column += 2;

View File

@ -20,7 +20,6 @@
#include "changes.h"
#include "lyxfont.h"
#include "ParagraphParameters.h"
#include "ShareContainer.h"
#include <boost/scoped_ptr.hpp>
@ -94,18 +93,25 @@ struct Paragraph::Pimpl {
struct FontTable {
///
FontTable(lyx::pos_type p, LyXFont const & f)
: pos_(p)
: pos_(p), font_(f)
{
#if 0
font_ = container.get(f);
#endif
}
///
lyx::pos_type pos() const { return pos_; }
///
void pos(lyx::pos_type p) { pos_ = p; }
///
LyXFont const & font() const { return *font_; }
LyXFont const & font() const { return font_; }
#if 0
///
void font(LyXFont const & f) { font_ = container.get(f);}
#else
///
void font(LyXFont const & f) { font_ = f;}
#endif
private:
/// End position of paragraph this font attribute covers
lyx::pos_type pos_;
@ -118,9 +124,13 @@ struct Paragraph::Pimpl {
The values LyXFont::IGNORE_* and LyXFont::TOGGLE are NOT
allowed in these font tables.
*/
#if 0
boost::shared_ptr<LyXFont> font_;
///
static ShareContainer<LyXFont> container;
#else
LyXFont font_;
#endif
};
///
friend struct matchFT;