~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to include/swobject.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef SWOBJECT_H
 
2
#define SWOBJECT_H
 
3
 
 
4
#include <utilfuns.h>
 
5
#if !defined(__GNUC__) && !defined(_WIN32_WCE)
 
6
#else
 
7
#include <unixstr.h>
 
8
#endif
 
9
 
 
10
#include <defs.h>
 
11
 
 
12
SWORD_NAMESPACE_START
 
13
#define SWDYNAMIC_CAST(className, object) (className *)((object)?((object->getClass()->isAssignableFrom(#className))?object:0):0)
 
14
 
 
15
/**
 
16
* Class used for SWDYNAMIC_CAST to save the inheritance order.
 
17
*/
 
18
class SWDLLEXPORT SWClass {
 
19
private:
 
20
        const char **descends;
 
21
 
 
22
public:
 
23
        SWClass(const char **descends) {
 
24
                this->descends = descends;
 
25
        }
 
26
 
 
27
        bool isAssignableFrom(const char *className) const {
 
28
                for (int i = 0; descends[i]; i++) {
 
29
                        if (!stricmp(descends[i], className))
 
30
                                return true;
 
31
                }
 
32
                return false;
 
33
        }
 
34
};
 
35
 
 
36
/** Base class for major Sword classes.
 
37
* SWObject is the base class for major Sword classes like SWKey.
 
38
* It is used because dynamic_cast is not available on all plattforms supported
 
39
* by Sword. Use SWDYNAMIC_CAST(classname, object) instead of dynamic_cast<classname>(object).
 
40
*/
 
41
class SWObject {
 
42
protected:
 
43
        SWClass * myclass;
 
44
     
 
45
public:
 
46
        /** Use this to get the class definition and inheritance order.
 
47
        * @return The class definition of this object
 
48
        */
 
49
        const SWClass *getClass () const {
 
50
                return myclass;
 
51
        }
 
52
};
 
53
 
 
54
SWORD_NAMESPACE_END
 
55
#endif