This moves the lastfiles global variable into LyX and makes 
emergencyCleanup a non-static member function.

Comments?

-- 
Angus
Index: src/BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.443
diff -u -p -r1.443 BufferView_pimpl.C
--- src/BufferView_pimpl.C	14 Oct 2003 13:01:38 -0000	1.443
+++ src/BufferView_pimpl.C	14 Oct 2003 16:28:32 -0000
@@ -255,7 +255,7 @@ bool BufferView::Pimpl::loadLyXFile(stri
 	bv_->showErrorList(_("Parse"));
 
 	if (tolastfiles)
-		lastfiles->newFile(b->fileName());
+		LyX::ref().lastfiles().newFile(b->fileName());
 
 	return true;
 }
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.1627
diff -u -p -r1.1627 ChangeLog
--- src/ChangeLog	14 Oct 2003 13:01:38 -0000	1.1627
+++ src/ChangeLog	14 Oct 2003 16:28:49 -0000
@@ -1,4 +1,17 @@
+2003-10-14  Angus Leeming  <[EMAIL PROTECTED]>
 
+	* lyx_main.[Ch]: make LyX a singleton class, accessible though the new
+	static member functions LyX::ref() and LyX::cref.
+	(lastfiles): new accessor functions for the new lastfiles_ member var.
+
+	* BufferView_pimpl.C (loadLyXFile):
+	* MenuBackend.C (expandLastfiles):
+	* bufferlist.C (MenuWrite, QuitLyX):
+	lastfiles is no longer a global variable.
+	Access through LyX::ref().lastfiles(), LyX::cref().lastfiles().
+
+	* boost.C (emergencyCleanup): LyX::emergencyCleanup is no longer a
+	static function. Access through LyX::cref().emergencyCleanup().
 
 2003-10-14  André Pönitz  <[EMAIL PROTECTED]>
 
Index: src/MenuBackend.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/MenuBackend.C,v
retrieving revision 1.90
diff -u -p -r1.90 MenuBackend.C
--- src/MenuBackend.C	9 Oct 2003 13:33:19 -0000	1.90
+++ src/MenuBackend.C	14 Oct 2003 16:28:51 -0000
@@ -375,9 +375,11 @@ string const limit_string_length(string 
 
 void expandLastfiles(Menu & tomenu, LyXView const * view)
 {
+	LastFiles const & lastfiles = LyX::cref().lastfiles();
+
 	int ii = 1;
-	LastFiles::const_iterator lfit = lastfiles->begin();
-	LastFiles::const_iterator end = lastfiles->end();
+	LastFiles::const_iterator lfit = lastfiles.begin();
+	LastFiles::const_iterator end = lastfiles.end();
 
 	for (; lfit != end && ii < 10; ++lfit, ++ii) {
 		string const label = tostr(ii) + ". "
Index: src/boost.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/boost.C,v
retrieving revision 1.6
diff -u -p -r1.6 boost.C
--- src/boost.C	21 Sep 2003 23:00:43 -0000	1.6
+++ src/boost.C	14 Oct 2003 16:28:51 -0000
@@ -40,7 +40,7 @@ void emergencyCleanup()
 
         didCleanup = true;
 
-        LyX::emergencyCleanup();
+        LyX::cref().emergencyCleanup();
 }
 
 }
Index: src/bufferlist.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferlist.C,v
retrieving revision 1.135
diff -u -p -r1.135 bufferlist.C
--- src/bufferlist.C	14 Oct 2003 11:35:49 -0000	1.135
+++ src/bufferlist.C	14 Oct 2003 16:28:51 -0000
@@ -179,7 +179,7 @@ bool BufferList::close(Buffer * buf, boo
 			if (!WriteAs(buf))
 				return false;
 		} else if (buf->save()) {
-			lastfiles->newFile(buf->fileName());
+			LyX::ref().lastfiles().newFile(buf->fileName());
 		} else {
 			return false;
 		}
Index: src/lyx_cb.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_cb.C,v
retrieving revision 1.228
diff -u -p -r1.228 lyx_cb.C
--- src/lyx_cb.C	9 Oct 2003 10:52:06 -0000	1.228
+++ src/lyx_cb.C	14 Oct 2003 16:28:52 -0000
@@ -90,7 +90,7 @@ bool quitting;	// flag, that we are quit
 bool MenuWrite(Buffer * buffer)
 {
 	if (buffer->save()) {
-		lastfiles->newFile(buffer->fileName());
+		LyX::ref().lastfiles().newFile(buffer->fileName());
 		return true;
 	}
 
@@ -184,7 +184,7 @@ void QuitLyX()
 		if (!bufferlist.quitWriteAll())
 			return;
 
-		lastfiles->writeFile(lyxrc.lastfiles);
+		LyX::cref().lastfiles().writeFile(lyxrc.lastfiles);
 	}
 
 	// Set a flag that we do quitting from the program,
Index: src/lyx_main.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_main.C,v
retrieving revision 1.180
diff -u -p -r1.180 lyx_main.C
--- src/lyx_main.C	13 Oct 2003 21:50:32 -0000	1.180
+++ src/lyx_main.C	14 Oct 2003 16:28:53 -0000
@@ -87,8 +87,6 @@ extern void QuitLyX();
 
 extern LyXServer * lyxserver;
 
-boost::scoped_ptr<LastFiles> lastfiles;
-
 // This is the global bufferlist object
 BufferList bufferlist;
 
@@ -105,9 +103,57 @@ void showFileError(string const & error)
 	exit(EXIT_FAILURE);
 }
 
+} // namespace anon
+
+
+boost::scoped_ptr<LyX> LyX::singleton_;
+
+void LyX::init(int & argc, char * argv[])
+{
+	BOOST_ASSERT(!singleton_.get());
+	// We must return from this before launching the gui so that
+	// other parts of the code can access singleton_ through
+	// LyX::ref and LyX::cref.
+	singleton_.reset(new LyX);
+	// Start the real execution loop.
+	singleton_->start(argc, argv);
+}
+ 
+
+LyX & LyX::ref()
+{
+	BOOST_ASSERT(singleton_.get());
+	return *singleton_.get();
+}
+
+
+LyX const & LyX::cref()
+{
+	BOOST_ASSERT(singleton_.get());
+	return *singleton_.get();
 }
 
-LyX::LyX(int & argc, char * argv[])
+
+LyX::LyX()
+	: first_start(false)
+{}
+
+
+LastFiles & LyX::lastfiles()
+{
+	BOOST_ASSERT(lastfiles_.get());
+	return *lastfiles_.get();
+}
+
+
+LastFiles const & LyX::lastfiles() const
+{
+	BOOST_ASSERT(lastfiles_.get());
+	return *lastfiles_.get();
+}
+
+
+void LyX::start(int & argc, char * argv[])
 {
 	// Here we need to parse the command line. At least
 	// we need to parse for "-dbg" and "-help"
@@ -226,7 +272,7 @@ static void error_handler(int err_sig)
 	signal(SIGTERM, SIG_DFL);
 	signal(SIGPIPE, SIG_DFL);
 
-	LyX::emergencyCleanup();
+	LyX::cref().emergencyCleanup();
 
 	lyxerr << "Bye." << endl;
 	if (err_sig!= SIGHUP &&
@@ -327,9 +373,9 @@ void LyX::init(bool gui)
 
 	lyxerr[Debug::INIT] << "Reading lastfiles `"
 			    << lyxrc.lastfiles << "'..." << endl;
-	lastfiles.reset(new LastFiles(lyxrc.lastfiles,
-				      lyxrc.check_lastfiles,
-				      lyxrc.num_lastfiles));
+	lastfiles_.reset(new LastFiles(lyxrc.lastfiles,
+				       lyxrc.check_lastfiles,
+				       lyxrc.num_lastfiles));
 }
 
 
@@ -391,7 +437,7 @@ void LyX::defaultKeyBindings(kb_keymap  
 }
 
 
-void LyX::emergencyCleanup()
+void LyX::emergencyCleanup() const
 {
 	// what to do about tmpfiles is non-obvious. we would
 	// like to delete any we find, but our lyxdir might
Index: src/lyx_main.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_main.h,v
retrieving revision 1.43
diff -u -p -r1.43 lyx_main.h
--- src/lyx_main.h	6 Oct 2003 15:42:21 -0000	1.43
+++ src/lyx_main.h	14 Oct 2003 16:28:53 -0000
@@ -21,25 +21,29 @@
 
 
 class ErrorItem;
-class LyXRC;
 class LastFiles;
-class Buffer;
 class kb_keymap;
 
 
-/// last files loaded
-extern boost::scoped_ptr<LastFiles> lastfiles;
-
-
 /// initial startup
 class LyX : boost::noncopyable {
 public:
-	LyX(int & argc, char * argv[]);
+	static void init(int & argc, char * argv[]);
+	static LyX & ref();
+	static LyX const & cref();
 
 	/// in the case of failure
-	static void emergencyCleanup();
+	void emergencyCleanup() const;
+
+	LastFiles & lastfiles();
+	LastFiles const & lastfiles() const;
 
 private:
+	static boost::scoped_ptr<LyX> singleton_;
+
+	LyX();
+	void start(int & argc, char * argv[]);
+
 	/// initial LyX set up
 	void init(bool);
 	/// set up the default key bindings
@@ -65,6 +69,9 @@ private:
 	bool first_start;
 	/// the parsed command line batch command if any
 	std::string batch_command;
+
+	/// last files loaded
+	boost::scoped_ptr<LastFiles> lastfiles_;
 };
 
 #endif // LYX_MAIN_H
Index: src/main.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/main.C,v
retrieving revision 1.26
diff -u -p -r1.26 main.C
--- src/main.C	16 Sep 2003 11:03:18 -0000	1.26
+++ src/main.C	14 Oct 2003 16:28:53 -0000
@@ -34,6 +34,6 @@ int main(int argc, char * argv[])
 	// initialize for internationalized version *EK*
 	locale_init();
 
-	LyX lyx(argc, argv);
+	LyX::init(argc, argv);
 	return 0;
 }
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.839
diff -u -p -r1.839 ChangeLog
--- src/frontends/xforms/ChangeLog	13 Oct 2003 12:25:11 -0000	1.839
+++ src/frontends/xforms/ChangeLog	14 Oct 2003 16:29:03 -0000
@@ -1,3 +1,8 @@
+2003-10-14  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* lyx_gui.C (LyX_XErrHandler): LyX::emergencyCleanup is no longer a
+	static function. Access through LyX::cref().emergencyCleanup().
+
 2003-10-13  Joao Luis Meloni Assirati <[EMAIL PROTECTED]>
 
 	* lyx_gui.C (set_datasocket_callback, set_serversocket_callback,
Index: src/frontends/xforms/lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/lyx_gui.C,v
retrieving revision 1.56
diff -u -p -r1.56 lyx_gui.C
--- src/frontends/xforms/lyx_gui.C	13 Oct 2003 12:25:11 -0000	1.56
+++ src/frontends/xforms/lyx_gui.C	14 Oct 2003 16:29:04 -0000
@@ -121,7 +121,7 @@ int LyX_XErrHandler(Display * display, X
 	}
 
 	// emergency cleanup
-	LyX::emergencyCleanup();
+	LyX::cref().emergencyCleanup();
 
 	// Get the reason for the crash.
 	char etxt[513];
Index: src/tex2lyx/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tex2lyx/ChangeLog,v
retrieving revision 1.37
diff -u -p -r1.37 ChangeLog
--- src/tex2lyx/ChangeLog	8 Oct 2003 11:31:51 -0000	1.37
+++ src/tex2lyx/ChangeLog	14 Oct 2003 16:29:06 -0000
@@ -1,3 +1,13 @@
+2003-10-14  Angus Leeming  <[EMAIL PROTECTED]>
+
+	* Makefile.am: move boost.C from the linked_files section
+	to the tex2lyx_SOURCES section.
+
+	* boost.C: new file. Simpler than the version in the main lyx source.
+	No reference to the emergencyCleanup stuff.
+
+	* tex2lyx.C: remove emergencyCleanup() stuff.
+
 2003-10-08  Angus Leeming  <[EMAIL PROTECTED]>
 
 	Fix doxygen warnings.
Index: src/tex2lyx/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tex2lyx/Makefile.am,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile.am
--- src/tex2lyx/Makefile.am	7 Aug 2003 22:59:53 -0000	1.13
+++ src/tex2lyx/Makefile.am	14 Oct 2003 16:29:06 -0000
@@ -16,7 +16,6 @@ bin_PROGRAMS = tex2lyx
 linked_files = \
 	FloatList.C \
 	Floating.C \
-	boost.C \
 	counters.C \
 	lyxlayout.h \
 	lyxlayout.C \
@@ -28,6 +27,7 @@ linked_files = \
 tex2lyx_SOURCES = \
 	$(linked_files) \
 	Spacing.h \
+	boost.C \
 	context.C \
 	context.h \
 	gettext.C \
Index: src/tex2lyx/boost.C
===================================================================
RCS file: src/tex2lyx/boost.C
diff -N src/tex2lyx/boost.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/tex2lyx/boost.C	14 Oct 2003 16:29:06 -0000
@@ -0,0 +1,41 @@
+/**
+ * \file boost.C
+ * 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.
+ */
+
+#include <config.h>
+
+#include "debug.h"
+
+#include <boost/assert.hpp>
+
+#include <cstdlib>
+#include <exception>
+
+using std::endl;
+
+namespace boost {
+
+void throw_exception(std::exception const & e)
+{
+	lyxerr << "Exception caught:\n"
+	       << e.what() << endl;
+	BOOST_ASSERT(false);
+}
+
+
+void assertion_failed(char const * expr, char const * function,
+		      char const * file, long line)
+{
+	lyxerr << "Assertion triggered in " << function
+	       << " by failing check \"" << expr << "\""
+	       << " in file " << file << ":" << line << endl;
+	::abort();
+}
+
+} // namespace boost
Index: src/tex2lyx/tex2lyx.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tex2lyx/tex2lyx.C,v
retrieving revision 1.50
diff -u -p -r1.50 tex2lyx.C
--- src/tex2lyx/tex2lyx.C	26 Sep 2003 14:27:20 -0000	1.50
+++ src/tex2lyx/tex2lyx.C	14 Oct 2003 16:29:07 -0000
@@ -16,7 +16,6 @@
 #include "context.h"
 
 #include "debug.h"
-#include "lyx_main.h"
 #include "lyxtextclass.h"
 #include "support/path_defines.h"
 #include "support/os.h"
@@ -42,8 +41,6 @@ using std::vector;
 
 // Hacks to allow the thing to link in the lyxlayout stuff
 LyXErr lyxerr(std::cerr.rdbuf());
-
-void LyX::emergencyCleanup() {}
 
 void handle_comment(Parser & p)
 {

Reply via email to