[sword-svn] r1736 - in trunk: examples/cmdline include src/mgr

scribe at crosswire.org scribe at crosswire.org
Fri Mar 4 10:52:56 MST 2005


Author: scribe
Date: 2005-03-04 10:52:56 -0700 (Fri, 04 Mar 2005)
New Revision: 1736

Modified:
   trunk/examples/cmdline/lookup.cpp
   trunk/include/swmgr.h
   trunk/src/mgr/swmgr.cpp
Log:
Added the ability for SWMgr to expose multiple copies of books


Modified: trunk/examples/cmdline/lookup.cpp
===================================================================
--- trunk/examples/cmdline/lookup.cpp	2005-03-04 17:35:52 UTC (rev 1735)
+++ trunk/examples/cmdline/lookup.cpp	2005-03-04 17:52:56 UTC (rev 1736)
@@ -15,7 +15,7 @@
 
 int main(int argc, char **argv)
 {
-	SWMgr manager;
+	SWMgr manager(0, 0, true, 0, true);
 	SWModule *target;
 	ModMap::iterator it;
 

Modified: trunk/include/swmgr.h
===================================================================
--- trunk/include/swmgr.h	2005-03-04 17:35:52 UTC (rev 1735)
+++ trunk/include/swmgr.h	2005-03-04 17:52:56 UTC (rev 1736)
@@ -68,14 +68,15 @@
 class SWDLLEXPORT SWMgr {
 
 private:
-	void commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr);
+	bool mgrModeMultiMod;
+	void commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod = false);
 
 protected:
 	SWFilterMgr *filterMgr;		//made protected because because BibleTime needs it
 	SWConfig * myconfig;		//made protected because because BibleTime needs it
 	SWConfig *mysysconfig;
 	SWConfig *homeConfig;
-	void CreateMods();
+	void CreateMods(bool multiMod = false);
 	SWModule *CreateMod(const char *name, const char *driver, ConfigEntMap & section);
 	void DeleteMods();
 	char configType;		// 0 = file; 1 = directory
@@ -125,9 +126,6 @@
 
 
 public:
-	virtual void augmentModules(const char *ipath);
-	void deleteModule(const char *);
-
 	/** Enable / Disable debug output on runtime
 	* Set this to true to get more verbose output of SWMgr at runtime. Set it to false to get no debug output.
 	* The default is "false".
@@ -192,12 +190,12 @@
 	* @param autoload If this bool is true the constructor starts loading the installed modules. If you reimplemented SWMgr you can set autoload=false to load the modules with your own reimplemented function.
 	* @param filterMgr an SWFilterMgr subclass to use to manager filters on modules THIS WILL BE DELETED BY SWMgr
 	*/
-	SWMgr(SWConfig * iconfig = 0, SWConfig * isysconfig = 0, bool autoload = true, SWFilterMgr *filterMgr = 0);
+	SWMgr(SWConfig * iconfig = 0, SWConfig * isysconfig = 0, bool autoload = true, SWFilterMgr *filterMgr = 0, bool multiMod = false);
 	/**
 	*
 	* @param filterMgr an SWFilterMgr subclass to use to manager filters on modules THIS WILL BE DELETED BY SWMgr
 	*/
-	SWMgr(SWFilterMgr *filterMgr);
+	SWMgr(SWFilterMgr *filterMgr, bool multiMod = false);
 	/**
 	*
 	* @param iConfigPath Path to config files.
@@ -208,13 +206,23 @@
 	* modules THIS WILL BE DELETED BY SWMgr
 	*
 	*/
-	SWMgr(const char *iConfigPath, bool autoload = true, SWFilterMgr *filterMgr = 0);
+	SWMgr(const char *iConfigPath, bool autoload = true, SWFilterMgr *filterMgr = 0, bool multiMod = false);
 	/** The destructor of SWMgr.
 	* This function cleans up the modules and deletes the created object.
 	* Destroy the SWMgr at last object in your application, because otherwise you may experience crashes
 	* because the SWModule objects become invalid.
 	*/
 	virtual ~SWMgr();
+
+	/**
+	* Adds books from a new path to the library
+	* @param path the path in which to search for books
+	* @param multiMod whether or not to keep multiple copies of the same book if found in different paths
+	*		default - false, uses last found version of the book
+	*/
+	virtual void augmentModules(const char *path, bool multiMod = false);
+	void deleteModule(const char *);
+
 	/**Installs a scan for modules in the directory givan as parameter.
 	* @param dir The directory where new modules should be searched.
 	*/

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2005-03-04 17:35:52 UTC (rev 1735)
+++ trunk/src/mgr/swmgr.cpp	2005-03-04 17:52:56 UTC (rev 1736)
@@ -243,17 +243,8 @@
 }
 
 
-SWMgr::SWMgr(SWFilterMgr *filterMgr) {
-	commonInit(0, 0, true, filterMgr);
-}
-
-
-SWMgr::SWMgr(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr) {
-	commonInit(iconfig, isysconfig, autoload, filterMgr);
-}
-
-
-void SWMgr::commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr) {
+void SWMgr::commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod) {
+	mgrModeMultiMod = multiMod;
 	this->filterMgr = filterMgr;
 	if (filterMgr)
 		filterMgr->setParentMgr(this);
@@ -276,8 +267,19 @@
 }
 
 
-SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr) {
+SWMgr::SWMgr(SWFilterMgr *filterMgr, bool multiMod) {
+	commonInit(0, 0, true, filterMgr, multiMod);
+}
 
+
+SWMgr::SWMgr(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod) {
+	commonInit(iconfig, isysconfig, autoload, filterMgr, multiMod);
+}
+
+
+SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr, bool multiMod) {
+
+	mgrModeMultiMod = multiMod;
 	SWBuf path;
 	
 	this->filterMgr = filterMgr;
@@ -542,7 +544,7 @@
 }
 
 
-void SWMgr::augmentModules(const char *ipath) {
+void SWMgr::augmentModules(const char *ipath, bool multiMod) {
 	SWBuf path = ipath;
 	if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
 		path += "/";
@@ -559,7 +561,7 @@
 		config = myconfig = 0;
 		loadConfigDir(configPath);
 
-		CreateMods();
+		CreateMods(multiMod);
 
 		stdstr(&prefixPath, savePrefixPath);
 		delete []savePrefixPath;
@@ -609,10 +611,10 @@
 		}
 		else	config->Load();
 
-		CreateMods();
+		CreateMods(mgrModeMultiMod);
 
 		for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) {
-			augmentModules(pathIt->c_str());
+			augmentModules(pathIt->c_str(), mgrModeMultiMod);
 		}
 //	augment config with ~/.sword/mods.d if it exists ---------------------
 		char *envhomedir  = getenv ("HOME");
@@ -621,7 +623,7 @@
 			if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
 				path += "/";
 			path += ".sword/";
-			augmentModules(path.c_str());
+			augmentModules(path.c_str(), mgrModeMultiMod);
 		}
 // -------------------------------------------------------------------------
 		if ( !Modules.size() ) // config exists, but no modules
@@ -934,7 +936,7 @@
 }
 
 
-void SWMgr::CreateMods() {
+void SWMgr::CreateMods(bool multiMod) {
 	SectionMap::iterator it;
 	ConfigEntMap::iterator start;
 	ConfigEntMap::iterator end;
@@ -962,7 +964,30 @@
 				AddRenderFilters(newmod, section);
 				AddEncodingFilters(newmod, section);
 				
-				Modules.insert(ModMap::value_type(newmod->Name(), newmod));
+				printf("Adding Module: %s\n", newmod->Name());
+				SWModule *oldmod = Modules[newmod->Name()];
+
+				if (oldmod) {
+					printf("Found an existing book with the same name\n");
+					if (!multiMod)
+						delete oldmod;
+					else {
+						printf("Keeping additional copy\n");
+						SWBuf name;
+						int i = 1; 
+						SWModule *mod;
+						do {
+							name = newmod->Name();
+							name.appendFormatted("_%d", i);
+							printf("Trying name: %s\n", name.c_str());
+							mod = Modules[name];
+							i++;
+						} while (mod);
+						newmod->Name(name);
+					}
+				}
+				printf("Inserting module: %s\n", newmod->Name());
+				Modules[newmod->Name()] = newmod;
 			}
 		}
 	}



More information about the sword-cvs mailing list