The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swgenbook.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * swgenbook.cpp - Implementation of SWGenBook class
4  *
5  * $Id: swgenbook.cpp 3808 2020-10-02 13:23:34Z scribe $
6  *
7  * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 
24 #include <swgenbook.h>
25 #include <versetreekey.h>
26 
28 
29 /******************************************************************************
30  * SWGenBook Constructor - Initializes data for instance of SWGenBook
31  *
32  * ENT: imodname - Internal name for module
33  * imoddesc - Name to display to user for module
34  * idisp - Display object to use for displaying
35  */
36 
37 SWGenBook::SWGenBook(const char *imodname, const char *imoddesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : SWModule(imodname, imoddesc, idisp, (char *)"Generic Books", enc, dir, mark, ilang) {
38  tmpTreeKey = 0;
39 }
40 
41 
42 /******************************************************************************
43  * SWGenBook Destructor - Cleans up instance of SWGenBook
44  */
45 
47  delete tmpTreeKey;
48 }
49 
50 
51 const TreeKey &SWGenBook::getTreeKey(const SWKey *k) const {
52  const SWKey* thiskey = k?k:this->key;
53 
54  const TreeKey *key = 0;
55 
56  SWTRY {
57  key = SWDYNAMIC_CAST(const TreeKey, (thiskey));
58  }
59  SWCATCH ( ... ) {}
60 
61  if (!key) {
62  const ListKey *lkTest = 0;
63  SWTRY {
64  lkTest = SWDYNAMIC_CAST(const ListKey, thiskey);
65  }
66  SWCATCH ( ... ) { }
67  if (lkTest) {
68  SWTRY {
69  key = SWDYNAMIC_CAST(const TreeKey, lkTest->getElement());
70  if (!key) {
71  const VerseTreeKey *tkey = 0;
72  SWTRY {
73  tkey = SWDYNAMIC_CAST(const VerseTreeKey, lkTest->getElement());
74  }
75  SWCATCH ( ... ) {}
76  if (tkey) key = tkey->getTreeKey();
77  }
78  }
79  SWCATCH ( ... ) { }
80  }
81  }
82  if (!key) {
83  const VerseTreeKey *tkey = 0;
84  SWTRY {
85  tkey = SWDYNAMIC_CAST(const VerseTreeKey, (thiskey));
86  }
87  SWCATCH ( ... ) {}
88  if (tkey) key = tkey->getTreeKey();
89  }
90 
91  if (!key) {
92  delete tmpTreeKey;
94  (*tmpTreeKey) = *(thiskey);
95  return (*tmpTreeKey);
96  }
97  else return *key;
98 }
99 
#define SWTextEncoding
Definition: swmodule.h:78
#define SWORD_NAMESPACE_START
Definition: defs.h:39
TreeKey * tmpTreeKey
Definition: swgenbook.h:41
virtual ~SWGenBook()
Definition: swgenbook.cpp:46
#define SWTRY
Definition: defs.h:57
virtual SWKey * getElement(int pos=-1)
Definition: listkey.cpp:270
#define SWCATCH(x)
Definition: defs.h:58
virtual SWKey * createKey() const =0
SWGenBook(const char *imodname=0, const char *imoddesc=0, SWDisplay *idisp=0, SWTextEncoding encoding=ENC_UNKNOWN, SWTextDirection dir=DIRECTION_LTR, SWTextMarkup markup=FMT_UNKNOWN, const char *ilang=0)
Definition: swgenbook.cpp:37
virtual TreeKey * getTreeKey()
const TreeKey & getTreeKey(const SWKey *k=0) const
Definition: swgenbook.cpp:51
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
#define SWTextDirection
Definition: swmodule.h:77
SWKey * key
Definition: swmodule.h:124
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
#define SWTextMarkup
Definition: swmodule.h:79