#ifndef TFN_BIBLE_H
#define TFN_BIBLE_H
#include <string>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#include "BibleAbbreviationsEn.h"
#include "BibleStructures.h"
namespace TearsForNations
{
//Event Types --
//ie: bool OnVerseFound(FullBibleVerse*){ }
typedef bool (*Bool_Function_FullVerse)(FullBibleVerse*);
class Bible
{
protected:
//Events
Bool_Function_FullVerse m_eventOnFoundBibleVerse;
public:
setEventOnFoundBibleVerse(Bool_Function_FullVerse fpt){m_eventOnFoundBibleVerse = fpt; }
public:
//*Constructor & Destructor
Bible(string version) : m_eventOnFoundBibleVerse(NULL), m_version(version), m_lastfound(""), m_lastfound_absolute_vs(0){}
virtual ~Bible(){}
//*Methods -- Derived classes should make sure to call m_eventOnFoundBibleVerse if it is not NULL
virtual const string& find(string str, int start_absolute_vs = 0) = 0;
virtual inline const string& findNext(const string& str)
{ return find(str, m_lastfound_absolute_vs + 1); }
virtual const std::vector<FullBibleVerse> findAll(string str, BibleSearchRange* pSearchRange = NULL) = 0;
virtual const string& getScripture(int bk, int ch, int vs) = 0;
virtual const string& getScripture(int absolute_vs) = 0;
//override these methods in Derived classes (each bible should contain such info)
virtual inline const string getDescription(){ return string(); }
virtual inline const string getAbbreviation(){ return m_version; }
virtual inline const string getComments(){ return string(); }
virtual inline const string getFont(){ return string(); }
virtual inline const string getFormat(){ return string(); }
virtual inline const string getStrongs(){ return string(); }
//*Accessors
virtual const string& getVersion(){ return m_version; }
const BibleVerse& getLastFoundVerse(){ return m_lastfound_verse_ref; }
const string& getLastFoundScripture(){ return m_lastfound; }
const int getLastFoundAbsoluteVerse(){ return m_lastfound_absolute_vs; }
static string BookToAbbr(int bk)
{
if (bk >= 1 && bk <= 66)
{
string abbr = "";
abbr += bible_book_en_abbr[bk][0];
//this next if statement will convert the 2nd char
//to lowercase if and only if the first is not a digit
//(ie. "1TI" becomes "1Ti", whereas "MAT" becomes "Mat"
if (!isdigit(bible_book_en_abbr[bk][0]))
{
abbr += tolower(bible_book_en_abbr[bk][1]);
}
else
{
abbr += bible_book_en_abbr[bk][1];
}
abbr += tolower(bible_book_en_abbr[bk][2]);
return abbr;
}
else return "";
}
static int AbbrToBook(char* abbr)
{
if (strlen(abbr) < 3){ return 0; }
for (int i = 1; i <= 66; ++i)
{
//all 3 letters match!
if (toupper(abbr[0]) == bible_book_en_abbr[i][0] &&
toupper(abbr[1]) == bible_book_en_abbr[i][1] &&
toupper(abbr[2]) == bible_book_en_abbr[i][2] )
{
return i;
}
}
return 0;
}
protected:
string m_version;
string m_lastfound;
int m_lastfound_absolute_vs;
BibleVerse m_lastfound_verse_ref;
// std::vector<BibleVerse> m_vct_verse_ref_history;
};
};
#endif //*TFN_BIBLE_H*//
Refactorings
No refactoring yet !
Tj Holowaychuk
August 6, 2009, August 06, 2009 22:37, permalink
bible searching? ... haha... usually programmers have enough logic not to be religious :P but hey
tearsfornations.blogspot.com
August 7, 2009, August 07, 2009 00:08, permalink
hmm, pacals wager seems pretty logical.
Ants
August 7, 2009, August 07, 2009 07:30, permalink
Yeah, but which god to believe in and how? Will belief in Yahweh, Allah, Jehovah, Odin, Kali be okay? What about belief in many gods -- might as well run multiple threads?
Anyway, stepping away from the precipice of a religious debate, here's me comments and some refactoring...
- Virtual methods should not be marked inline. In theory the compiler should know not to treat virtual methods as inline because a vtable needs to be built, but why confuse the reader?
- Changed find() and findNext() to return const FullBibleVerse just like findAll() to keep them all consistent.
- If getDescription/Abbreviation/Comments/Font/Format/Strongs() should be overriden by the derived classes, the mark methods as pure virtual instead of providing default implementations.
- Changed setEventOnFoundBibleVerse() to return the old value so that event handlers can be chained together.
- If version is passed into the constructor, why is there a need for getVersion() to be virtual?
- Tagged getVersion/LastFoundVerse/LastFoundScripture/LastFoundAbsoluteVerse() to be const since these shouldn't change the state of the object.
- Made BookToAbbr() and AbbrToBook() pure virtual methods because not all bibles have 66 books. It'll depend on which version of the Bible.
Originally, I was thinking of changing int bk to be enum Book, but then it reopens the can of worms of what is a definitive list of books?
#ifndef TFN_BIBLE_H
#define TFN_BIBLE_H
#include <string>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#include "BibleAbbreviationsEn.h"
#include "BibleStructures.h"
namespace TearsForNations
{
//Event Types --
//ie: bool OnVerseFound(const FullBibleVerse&){ }
typedef bool (*Bool_Function_FullVerse)(const FullBibleVerse&);
class Bible
{
protected:
//Events
Bool_Function_FullVerse m_eventOnFoundBibleVerse;
public:
Bible(string version)
: m_eventOnFoundBibleVerse(NULL)
, m_version(version)
, m_lastfound("")
, m_lastfound_absolute_vs(0)
{
}
virtual ~Bible()
{
}
//*Methods -- Derived classes should make sure to call m_eventOnFoundBibleVerse if it is not NULL
virtual const FullBibleVerse& find(string str, int start_absolute_vs = 0) = 0;
virtual const FullBibleVerse& findNext(const string& str)
{
return find(str, m_lastfound_absolute_vs + 1);
}
virtual const std::vector<const FullBibleVerse&> findAll(string str, BibleSearchRange* pSearchRange = NULL) = 0;
//override these methods in Derived classes (each bible should contain such info)
virtual const string& getScripture(int bk, int ch, int vs) = 0;
virtual const string& getScripture(int absolute_vs) = 0;
virtual const string getDescription() = 0;
virtual const string getAbbreviation() = 0;
virtual const string getComments() = 0;
virtual const string getFont() = 0;
virtual const string getFormat() = 0;
virtual const string getStrongs() = 0;
virtual string BookToAbbr(int bk) = 0;
virtual int AbbrToBook(const char* abbr) = 0;
//*Accessors
Bool_Function_FullVerse inline setEventOnFoundBibleVerse(Bool_Function_FullVerse fpt)
{
Bool_Function_FullVerse old = m_eventOnFoundBibleVerse;
m_eventOnFoundBibleVerse = fpt;
return old;
}
const string& getVersion() const
{
return m_version;
}
const BibleVerse& getLastFoundVerse() const
{
return m_lastfound_verse_ref;
}
const string& getLastFoundScripture() const
{
return m_lastfound;
}
const int getLastFoundAbsoluteVerse() const
{
return m_lastfound_absolute_vs;
}
protected:
string m_version;
string m_lastfound;
int m_lastfound_absolute_vs;
BibleVerse m_lastfound_verse_ref;
};
};
#endif //*TFN_BIBLE_H*//
tearsfornations.blogspot.com
August 8, 2009, August 08, 2009 19:12, permalink
oh oh i know!!! believe in JESUS!!!
tearsfornations.blogspot.com
August 8, 2009, August 08, 2009 19:17, permalink
oh yes, by the way there are 66 books in the bible, from Genesis to Revelation, all testifying of the one true God and His Son Jesus Christ
I think an enum is probably a good idea! thanks!
code works, just an idea for a bible searching framework --
got any more method suggestions?