1 /****************************************************************************** 2 * 3 * versification.h - definition of class VersificationMgr used for managing 4 * versification systems 5 * 6 * $Id: versificationmgr.h 3240 2014-07-12 16:27:35Z scribe $ 7 * 8 * Copyright 2008-2013 CrossWire Bible Society (http://www.crosswire.org) 9 * CrossWire Bible Society 10 * P. O. Box 2528 11 * Tempe, AZ 85280-2528 12 * 13 * This program is free software; you can redistribute it and/or modify it 14 * under the terms of the GNU General Public License as published by the 15 * Free Software Foundation version 2. 16 * 17 * This program is distributed in the hope that it will be useful, but 18 * WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 * General Public License for more details. 21 * 22 */ 23 24 #include <list> 25 #include <defs.h> 26 #include <swcacher.h> 27 #include <swbuf.h> 28 29 30 #ifndef VERSIFICATIONMGR_H 31 #define VERSIFICATIONMGR_H 32 33 34 SWORD_NAMESPACE_START 35 36 typedef std::list <SWBuf>StringList; 37 38 struct sbook; 39 class TreeKey; 40 41 42 struct abbrev 43 { 44 const char *ab; 45 const char *osis; 46 }; 47 48 struct sbook { 49 /**Name of book 50 */ 51 const char *name; 52 53 /**OSIS name 54 */ 55 const char *osis; 56 57 /**Preferred Abbreviation 58 */ 59 const char *prefAbbrev; 60 61 /**Maximum chapters in book 62 */ 63 unsigned char chapmax; 64 /** Array[chapmax] of maximum verses in chapters 65 */ 66 int *versemax; 67 }; 68 69 70 class SWDLLEXPORT VersificationMgr : public SWCacher { 71 72 73 public: 74 class System; 75 76 private: 77 friend class __staticsystemVersificationMgr; 78 79 class Private; 80 Private *p; 81 82 void init(); 83 84 protected: 85 static VersificationMgr *systemVersificationMgr; 86 87 public: 88 class SWDLLEXPORT Book { 89 friend class System; 90 friend struct BookOffsetLess; 91 class Private; 92 Private *p; 93 94 /** book name */ 95 SWBuf longName; 96 97 /** OSIS Abbreviation */ 98 SWBuf osisName; 99 100 /** Preferred Abbreviation */ 101 SWBuf prefAbbrev; 102 103 /** Maximum chapters in book */ 104 unsigned int chapMax; 105 106 void init(); 107 108 public: Book()109 Book() { init(); } 110 Book(const Book &other); 111 Book &operator =(const Book &other); Book(const char * longName,const char * osisName,const char * prefAbbrev,int chapMax)112 Book(const char *longName, const char *osisName, const char *prefAbbrev, int chapMax) { 113 this->longName = longName; 114 this->osisName = osisName; 115 this->prefAbbrev = prefAbbrev; 116 this->chapMax = chapMax; 117 init(); 118 } 119 ~Book(); getLongName()120 const char *getLongName() const { return longName.c_str(); } getOSISName()121 const char *getOSISName() const { return osisName.c_str(); } getPreferredAbbreviation()122 const char *getPreferredAbbreviation() const { return prefAbbrev.c_str(); } getChapterMax()123 int getChapterMax() const { return chapMax; } 124 int getVerseMax(int chapter) const; 125 }; 126 127 class SWDLLEXPORT System { 128 class Private; 129 Private *p; 130 SWBuf name; 131 int BMAX[2]; 132 long ntStartOffset; 133 void init(); 134 public: System()135 System() { this->name = ""; init(); } 136 System(const System &other); 137 System &operator =(const System &other); System(const char * name)138 System(const char *name) { this->name = name; init(); } 139 ~System(); getName()140 const char *getName() const { return name.c_str(); } 141 const Book *getBookByName(const char *bookName) const; 142 int getBookNumberByOSISName(const char *bookName) const; 143 const Book *getBook(int number) const; 144 int getBookCount() const; 145 void loadFromSBook(const sbook *ot, const sbook *nt, int *chMax, const unsigned char *mappings=NULL); 146 long getOffsetFromVerse(int book, int chapter, int verse) const; 147 char getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const; getBMAX()148 const int *getBMAX() const { return BMAX; }; getNTStartOffset()149 long getNTStartOffset() const { return ntStartOffset; } 150 void translateVerse(const System *dstSys, const char **book, int *chapter, int *verse, int *verse_end) const; 151 }; VersificationMgr()152 VersificationMgr() { init(); } 153 ~VersificationMgr(); 154 static VersificationMgr *getSystemVersificationMgr(); 155 static void setSystemVersificationMgr(VersificationMgr *newVersificationMgr); 156 const StringList getVersificationSystems() const; 157 const System *getVersificationSystem(const char *name) const; 158 void registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax, const unsigned char *mappings=NULL); 159 void registerVersificationSystem(const char *name, const TreeKey *); 160 }; 161 162 SWDLLEXPORT extern const struct abbrev builtin_abbrevs[]; 163 164 SWORD_NAMESPACE_END 165 #endif 166