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