1 /********************************************************************************
2 *                                                                               *
3 *                         T o p l e v e l   O b j e c t                         *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2021 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify          *
9 * it under the terms of the GNU Lesser General Public License as published by   *
10 * the Free Software Foundation; either version 3 of the License, or             *
11 * (at your option) any later version.                                           *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
16 * GNU Lesser General Public License for more details.                           *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public License      *
19 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
20 ********************************************************************************/
21 #include "xincs.h"
22 #include "fxver.h"
23 #include "fxdefs.h"
24 #include "FXArray.h"
25 #include "FXHash.h"
26 #include "FXStream.h"
27 #include "FXObject.h"
28 #include "FXElement.h"
29 #include "FXException.h"
30 
31 
32 /*
33   Notes:
34 
35   - FXObject is the top of the class hierarchy.  Metaclass for FXObject can
36     not be made by the macros, so do it by hand.
37   - Message dispatch using tryHandle() catches all resource exceptions; this
38     is so that if such exceptions are thrown, resources can be reclaimed during
39     the unroll to the widget calling tryHandle, at which point we can proceed
40     normally since this was the last-known-good point.
41     Thus a simple mechanism is created whereby properly written FOX programs
42     can recover gracefully from resource limitation driven exceptions.
43 */
44 
45 using namespace FX;
46 
47 namespace FX {
48 
49 /*******************************************************************************/
50 
51 // Have to do this one `by hand' as it has no base class
52 const FXMetaClass FXObject::metaClass("FXObject",FXObject::manufacture,NULL,NULL,0,0);
53 
54 
55 // Build an object
manufacture()56 FXObject* FXObject::manufacture(){
57   return new FXObject;
58   }
59 
60 
61 // Get class name of object
getClassName() const62 const FXchar* FXObject::getClassName() const {
63   return getMetaClass()->getClassName();
64   }
65 
66 
67 // Check if object belongs to a class
isMemberOf(const FXMetaClass * metaclass) const68 FXbool FXObject::isMemberOf(const FXMetaClass* metaclass) const {
69   return getMetaClass()->isSubClassOf(metaclass);
70   }
71 
72 
73 // Try handle message safely; we catch only resource exceptions, things like
74 // running out of memory, window handles, system resources; others are ignored.
tryHandle(FXObject * sender,FXSelector sel,void * ptr)75 long FXObject::tryHandle(FXObject* sender,FXSelector sel,void* ptr){
76   try { return handle(sender,sel,ptr); } catch(const FXResourceException&) { return 0; }
77   }
78 
79 
80 // Save to stream
save(FXStream &) const81 void FXObject::save(FXStream&) const { }
82 
83 
84 // Load from stream
load(FXStream &)85 void FXObject::load(FXStream&){ }
86 
87 
88 // Unhandled function
onDefault(FXObject *,FXSelector,void *)89 long FXObject::onDefault(FXObject*,FXSelector,void*){ return 0; }
90 
91 
92 // Handle message
handle(FXObject * sender,FXSelector sel,void * ptr)93 long FXObject::handle(FXObject* sender,FXSelector sel,void* ptr){
94   return onDefault(sender,sel,ptr);
95   }
96 
97 
98 // Virtual destructor
~FXObject()99 FXObject::~FXObject(){
100   }
101 
102 }
103