Does anyone know why these are boost::shared_ptrs? I don't myself see any reason for this in the current implementation, and I think am pretty sure it can be the source of bugs. Reason: DocumentClass objects are created from BaseClass objects. But now all such objects share a single floatlist_ which can, however, be modified by modules. Each DocumentClass should have its own one of these, it seems to me.
That said, I'm a bit puzzled by the long comment by Lars at the start of FloatList.cpp. I think, but I am not absolutely sure, that this is not really an issue now.
The attached patch therefore gets rid of that and so, together with the LayoutPtr patch, would completely get rid of boost::shared_ptr from TextClass.
Comments? rh
Index: src/TextClass.h =================================================================== --- src/TextClass.h (revision 23512) +++ src/TextClass.h (working copy) @@ -11,6 +11,8 @@ #define TEXTCLASS_H #include "ColorCode.h" +#include "Counters.h" +#include "FloatList.h" #include "FontInfo.h" #include "LayoutEnums.h" #include "LayoutPtr.h" @@ -20,8 +22,6 @@ #include "support/docstring.h" #include "support/types.h" -#include <boost/shared_ptr.hpp> - #include <list> #include <map> #include <set> @@ -137,9 +137,9 @@ /// document class description std::string description_; /// available types of float, eg. figure, algorithm. - boost::shared_ptr<FloatList> floatlist_; + mutable FloatList floatlist_; /// Types of counters, eg. sections, eqns, figures, avail. in document class. - boost::shared_ptr<Counters> counters_; + mutable Counters counters_; /// Has this layout file been loaded yet? mutable bool loaded_; /// Is the TeX class available? @@ -189,7 +189,7 @@ /// The name of the title command std::string titlename_; /// Input layouts available to this layout - mutable InsetLayouts insetlayoutlist_; + InsetLayouts insetlayoutlist_; /// The minimal TocLevel of sectioning layouts int min_toclevel_; /// The maximal TocLevel of sectioning layouts @@ -239,7 +239,7 @@ /// A DocumentClass nevers count as loaded, since it is dynamic virtual bool loaded() { return false; } /// Inset layouts of this doc class - InsetLayouts & insetLayouts() const { return insetlayoutlist_; }; + InsetLayouts const & insetLayouts() const { return insetlayoutlist_; }; /// \return the layout object of an inset given by name. If the name /// is not found as such, the part after the ':' is stripped off, and /// searched again. In this way, an error fallback can be provided: @@ -256,12 +256,12 @@ // accessors /////////////////////////////////////////////////////////////////// /// the list of floats defined in the document class - FloatList & floats() { return *floatlist_.get(); } + //FloatList & floats() { return floatlist_; } /// the list of floats defined in the document class - FloatList const & floats() const { return *floatlist_.get(); } - /// The Counters present in this document class. - Counters & counters() const { return *counters_.get(); } + FloatList const & floats() const { return floatlist_; } /// + Counters & counters() const { return counters_; } + /// std::string const & opt_fontsize() const { return opt_fontsize_; } /// std::string const & opt_pagestyle() const { return opt_pagestyle_; } Index: src/TextClass.cpp =================================================================== --- src/TextClass.cpp (revision 23512) +++ src/TextClass.cpp (working copy) @@ -114,8 +114,6 @@ TextClass::TextClass() { - floatlist_ = boost::shared_ptr<FloatList>(new FloatList); - counters_ = boost::shared_ptr<Counters>(new Counters); outputType_ = LATEX; columns_ = 1; sides_ = OneSide; @@ -470,7 +468,7 @@ case TC_NOFLOAT: if (lexrc.next()) { string const nofloat = lexrc.getString(); - floatlist_->erase(nofloat); + floatlist_.erase(nofloat); } break; } @@ -713,8 +711,8 @@ case FT_TYPE: lexrc.next(); type = lexrc.getString(); - if (floatlist_->typeExist(type)) { - Floating const & fl = floatlist_->getType(type); + if (floatlist_.typeExist(type)) { + Floating const & fl = floatlist_.getType(type); placement = fl.placement(); ext = fl.ext(); within = fl.within(); @@ -764,13 +762,13 @@ if (getout) { Floating fl(type, placement, ext, within, style, name, listName, builtin); - floatlist_->newFloat(fl); + floatlist_.newFloat(fl); // each float has its own counter - counters_->newCounter(from_ascii(type), from_ascii(within), + counters_.newCounter(from_ascii(type), from_ascii(within), docstring(), docstring()); // also define sub-float counters docstring const subtype = "sub-" + from_ascii(type); - counters_->newCounter(subtype, from_ascii(type), + counters_.newCounter(subtype, from_ascii(type), "\\alph{" + subtype + "}", docstring()); } @@ -817,7 +815,7 @@ case CT_NAME: lexrc.next(); name = lexrc.getDocString(); - if (counters_->hasCounter(name)) + if (counters_.hasCounter(name)) LYXERR(Debug::TCLASS, "Reading existing counter " << to_utf8(name)); else LYXERR(Debug::TCLASS, "Reading new counter " << to_utf8(name)); @@ -845,7 +843,7 @@ // Here if have a full counter if getout == true if (getout) - counters_->newCounter(name, within, + counters_.newCounter(name, within, labelstring, labelstring_appendix); lexrc.popTable(); @@ -933,9 +931,11 @@ InsetLayout const & DocumentClass::insetLayout(docstring const & name) const { docstring n = name; + InsetLayouts::const_iterator cen = insetlayoutlist_.end(); while (!n.empty()) { - if (insetlayoutlist_.count(n) > 0) - return insetlayoutlist_[n]; + InsetLayouts::const_iterator cit = insetlayoutlist_.lower_bound(n); + if (cit != cen && cit->first == n) + return cit->second; size_t i = n.find(':'); if (i == string::npos) break;