LayoutFile const & BaseClassList::operator[](string const & classname) const
{
BOOST_ASSERT(haveClass(classname));
- return classmap_[classname];
+ return *classmap_[classname];
}
BaseClassList::operator[](string const & classname)
{
BOOST_ASSERT(haveClass(classname));
- return classmap_[classname];
+ return *classmap_[classname];
}
LYXERR(Debug::TCLASS, "Avail: " << avail);
// This code is run when we have
// fname, clname, desc, and avail
- LayoutFile tmpl(fname, clname, desc, avail);
+ LayoutFile * tmpl = new LayoutFile(fname, clname, desc, avail);
if (lyxerr.debugging(Debug::TCLASS)) {
// only system layout files are loaded here so no
// buffer path is needed.
- tmpl.load();
+ tmpl->load();
}
classmap_[fname] = tmpl;
}
void BaseClassList::reset(LayoutFileIndex const & classname) {
BOOST_ASSERT(haveClass(classname));
- LayoutFile const & tc = classmap_[classname];
- LayoutFile tmpl(tc.name(), tc.latexname(), tc.description(),
- tc.isTeXClassAvailable());
+ LayoutFile * tc = classmap_[classname];
+ LayoutFile * tmpl =
+ new LayoutFile(tc->name(), tc->latexname(), tc->description(),
+ tc->isTeXClassAvailable());
classmap_[classname] = tmpl;
+ delete tc;
}
// returns: whole string, classtype (not used here), class name, description
BOOST_ASSERT(sub.size() == 4);
// now, create a TextClass with description containing path information
- LayoutFile tmpl(textclass, sub.str(2) == "" ? textclass : sub.str(2),
- sub.str(3) + " <" + path + ">", true);
- classmap_[localIndex] = tmpl;
+ string className(sub.str(2) == "" ? textclass : sub.str(2));
+ string description(sub.str(3) + " <" + path + ">");
+ LayoutFile * tmpl =
+ new LayoutFile(textclass, className, description, true);
// This textclass is added on request so it will definitely be
// used. Load it now because other load() calls may fail if they
// are called in a context without buffer path information.
- classmap_[localIndex].load(path);
+ tmpl->load(path);
+ classmap_[localIndex] = tmpl;
return localIndex;
}
}
#include "support/strfwd.h"
+#include <boost/noncopyable.hpp>
+
#include <vector>
/// This class amounts to little more than a `strong typedef'.
/// A LayoutFile represents the layout information that is
/// contained in a *.layout file.
-class LayoutFile : public TextClass {
+class LayoutFile : public TextClass, boost::noncopyable {
public:
- /// This should never be used, but it has to be provided for
- /// std::map operator[] to work. Something like:
- /// mapthingy[stuff] = otherthing
- /// creates an empty object before doing the assignment.
- LayoutFile() {}
/// check whether the TeX class is available
bool isTeXClassAvailable() const { return texClassAvail_; }
private:
/// Construct a layout with default values. Actual values loaded later.
- explicit LayoutFile(std::string const &,
- std::string const & = std::string(),
- std::string const & = std::string(),
- bool texClassAvail = false);
+ explicit LayoutFile(std::string const & filename,
+ std::string const & className = std::string(),
+ std::string const & description = std::string(),
+ bool texClassAvail = false);
/// The only class that should create a LayoutFile is
/// BaseClassList, which calls the private constructor.
friend class BaseClassList;
+ /// can't create empty LayoutFile
+ LayoutFile() {};
};
static std::string const localPrefix;
private:
///
- typedef std::map<std::string, LayoutFile> ClassMap;
+ typedef std::map<std::string, LayoutFile *> ClassMap;
/// noncopyable
BaseClassList(BaseClassList const &);
/// nonassignable
DocumentClass & DocumentClassBundle::newClass(LayoutFile const & baseClass)
{
- DocumentClass dc(baseClass);
+ DocumentClass * dc = new DocumentClass(baseClass);
tc_list_.push_back(dc);
- return tc_list_.back();
+ return *tc_list_.back();
}
#include "support/docstring.h"
#include "support/types.h"
+#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <list>
class LayoutFile;
class Lexer;
+/// Based upon ideas in boost::noncopyable, inheriting from this
+/// class effectively makes the copy constructor protected but the
+/// assignment constructor private.
+class ProtectCopy
+{
+protected:
+ ProtectCopy() {}
+ ~ProtectCopy() {}
+ ProtectCopy(const ProtectCopy &) {};
+private:
+ const ProtectCopy & operator=(const ProtectCopy &);
+};
+
/// A TextClass represents a collection of layout information: At the
/// moment, this includes Layout's and InsetLayout's.
/// Simple TextClass objects are not directly constructed in the main
/// LyX code---the constructor is protected. (That said, in tex2lyx
/// there are what amount to simple TextClass objects.)
-class TextClass {
+class TextClass : protected ProtectCopy {
public:
///
virtual ~TextClass() {};
///
/// In the main LyX code, DocumentClass objects are created only by
/// DocumentClassBundle, for which see below.
-class DocumentClass : public TextClass {
+class DocumentClass : public TextClass, boost::noncopyable {
public:
///
virtual ~DocumentClass() {}
DocumentClass() {};
private:
/// The only class that can create a DocumentClass is
- /// DocumentClassBundle, which calls the private constructor.
+ /// DocumentClassBundle, which calls the protected constructor.
friend class DocumentClassBundle;
///
static InsetLayout empty_insetlayout_;
///
/// This is a singleton class. Its sole instance is accessed via
/// DocumentClassBundle::get().
-class DocumentClassBundle {
+class DocumentClassBundle : boost::noncopyable {
public:
/// \return Pointer to a new class equal to baseClass
DocumentClass & newClass(LayoutFile const & baseClass);
private:
/// control instantiation
DocumentClassBundle() {}
- /// noncopyable
- DocumentClassBundle(DocumentClassBundle const &);
///
- std::list<DocumentClass> tc_list_;
+ std::list<DocumentClass *> tc_list_;
};
} // anonymous namespace
-TeX2LyXDocClass const parse_preamble(Parser & p, ostream & os, string const & forceclass)
+void parse_preamble(Parser & p, ostream & os,
+ string const & forceclass, TeX2LyXDocClass & tc)
{
// initialize fixed types
special_columns['D'] = 3;
cerr << "Error: Could not find layout file for textclass \"" << h_textclass << "\"." << endl;
exit(1);
}
- TeX2LyXDocClass textclass;
- textclass.read(layoutfilename);
+ tc.read(layoutfilename);
if (h_papersides.empty()) {
ostringstream ss;
- ss << textclass.sides();
+ ss << tc.sides();
h_papersides = ss.str();
}
- end_preamble(os, textclass);
- return textclass;
+ end_preamble(os, tc);
}
// }])
//p.dump();
stringstream ss;
- TeX2LyXDocClass textclass = parse_preamble(p, ss, documentclass);
+ TeX2LyXDocClass textclass;
+ parse_preamble(p, ss, documentclass, textclass);
captionlayout = LayoutPtr(Layout::forCaption());
active_environments.push_back("document");
{};
/// in preamble.cpp
-TeX2LyXDocClass const parse_preamble(Parser & p, std::ostream & os, std::string const & forceclass);
+void parse_preamble(Parser & p, std::ostream & os,
+ std::string const & forceclass, TeX2LyXDocClass & tc);
/// used packages with options
extern std::map<std::string, std::vector<std::string> > used_packages;