ScummVM API documentation
base_object.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA_SHARED_CORE_BASE_OBJECT_H
23 #define ULTIMA_SHARED_CORE_BASE_OBJECT_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "common/hash-str.h"
28 #include "common/list.h"
29 #include "ultima/shared/core/file.h"
30 
31 namespace Ultima {
32 namespace Shared {
33 
34 class BaseObject;
35 
36 class ClassDef;
37 typedef ClassDef(*ClassDefFn)();
38 
43 class ClassDef {
44 private:
45  ClassDefFn _parentFn;
46 public:
47  const char *_className;
48 public:
49  ClassDef(const char *className, const ClassDefFn parentFn) :
50  _className(className), _parentFn(parentFn) {
51  }
52 
53  bool hasParent() const {
54  return _parentFn != nullptr;
55  }
56  ClassDef parent() const {
57  return (*_parentFn)();
58  }
59  bool operator==(const ClassDef &right) const {
60  return !strcmp(_className, right._className);
61  }
62 };
63 
64 #define CLASSDEF \
65  static ::Ultima::Shared::ClassDef type(); \
66  ::Ultima::Shared::ClassDef getType() const override { return type(); }
67 
71 class BaseObject {
72 public:
73  static ::Ultima::Shared::ClassDef type();
74  virtual ::Ultima::Shared::ClassDef getType() const { return type(); }
75  virtual ~BaseObject() {
76  }
77 
82  bool isInstanceOf(const ClassDef &classDef) const;
83 };
84 
85 } // End of namespace Shared
86 } // End of namespace Ultima
87 
88 #endif
Definition: detection.h:27
Definition: base_object.h:43
Definition: base_object.h:71