Difference between revisions of "DevTools:Code Examples"

From CrossWire Bible Society
Jump to: navigation, search
m (SWORD code examples for supported languages)
m (moved Code Examples to DevTools:Code Examples: To keep things consistent.)
(No difference)

Revision as of 04:18, 2 August 2009


This page was started to provoke developers who know how the SWORD API works to post simple, everyday code examples that anyone can use. By "simple" I mean something that can work within a static function if possible.

Examples

C++

Get Modules Example(s)

The following example is for obtaining modules that are installed in the user's SWORD repository. This example also makes slight use of the Qt4 GUI library. The following function takes one parameter, the type of the modules you want to retrieve. Unless stated otherwise, there are up to 4 different types to choose from:

  • "Biblical Texts"
  • "Commentaries"
  • "Lexicons / Dictionaries"
  • "Generic Books"

Code

#include <QStringList>
#include <swmgr.h>
#include <swmodule.h>

QStringList getModules(const char* modType)
	{
		QStringList modules;
		SWMgr library;
		ModMap::iterator it;

		for (it = library.Modules.begin(); it != library.Modules.end(); it++)
		{
			SWModule *module = (*it).second;
			if (!strcmp(module->Type(), modType))
				modules << module->Name();
		}

		return modules;
	}

Example Usage

QStringList bibles = getModules("Biblical Texts");

Python

Java