|
| 1 | +// |
| 2 | +// MulleDynamicObject.m |
| 3 | +// MulleObjC |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Nat! - Mulle kybernetiK. |
| 6 | +// Copyright (c) 2020 Codeon GmbH. |
| 7 | +// All rights reserved. |
| 8 | +// |
| 9 | +// |
| 10 | +// Redistribution and use in source and binary forms, with or without |
| 11 | +// modification, are permitted provided that the following conditions are met: |
| 12 | +// |
| 13 | +// Redistributions of source code must retain the above copyright notice, this |
| 14 | +// list of conditions and the following disclaimer. |
| 15 | +// |
| 16 | +// Redistributions in binary form must reproduce the above copyright notice, |
| 17 | +// this list of conditions and the following disclaimer in the documentation |
| 18 | +// and/or other materials provided with the distribution. |
| 19 | +// |
| 20 | +// Neither the name of Mulle kybernetiK nor the names of its contributors |
| 21 | +// may be used to endorse or promote products derived from this software |
| 22 | +// without specific prior written permission. |
| 23 | +// |
| 24 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 25 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 28 | +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 29 | +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 30 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 31 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 32 | +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | +// POSSIBILITY OF SUCH DAMAGE. |
| 35 | +// |
| 36 | +#import "NSObject.h" |
| 37 | + |
| 38 | +#import "NSMutableCopying.h" |
| 39 | + |
| 40 | +// |
| 41 | +// The convenient superclass of all "non-value" and "non-container" objects. |
| 42 | +// |
| 43 | +// This allows us to add properties via categories. |
| 44 | +// You declare them with @property( dynamic) int foo; in the @interface |
| 45 | +// and @dynamic foo; in the @implementation of a category on MulleDynamicObject. |
| 46 | +// |
| 47 | +// For this scheme to work, there must be NSValue and NSNumber classes present |
| 48 | +// in the runtime. Otherwise you can only store NSInteger, NSUInteger, char * |
| 49 | +// and any object (but not NSRange or floating point values or any integer |
| 50 | +// exceeding the sizeof( void *) |
| 51 | +// |
| 52 | +@interface MulleDynamicObject : NSObject < NSMutableCopying> |
| 53 | +{ |
| 54 | + struct mulle__pointermap __ivars; // use __ to "hide" it |
| 55 | +} |
| 56 | + |
| 57 | +// |
| 58 | +// You MUST NOT call [super forward:] to inherit this. See NSObject |
| 59 | +// forward: for more details |
| 60 | +// |
| 61 | +- (void *) forward:(void *) args; |
| 62 | + |
| 63 | + |
| 64 | +// |
| 65 | +// -isFullyDynamic set to YES creates descriptors on the fly |
| 66 | +// and guesses their type to be id. |
| 67 | +// The created descriptors are global and will affect everything. If your |
| 68 | +// registration of -myIntValue comes later in a NSBundle, it's tough luck. |
| 69 | +// The signature is already set to '@'. |
| 70 | +// |
| 71 | +// -isFullyDynamic is a non-thread safe global for performance reasons. |
| 72 | +// |
| 73 | +// Only override with a category!, don't override in a subclass! (As this |
| 74 | +// would obscure the actual extent of what this does). The idea is that |
| 75 | +// this is a global switch, that will affect all objects in the program. |
| 76 | +// It's supposed to be a "design" decision. |
| 77 | +// |
| 78 | ++ (BOOL) isFullyDynamic; |
| 79 | + |
| 80 | +@end |
| 81 | + |
| 82 | + |
| 83 | +MULLE_C_NONNULL_FIRST_FOURTH |
| 84 | +void _MulleDynamicObjectValueSetter( MulleDynamicObject *self, SEL _cmd, void *_param, char *objcType); |
| 85 | + |
| 86 | +MULLE_C_NONNULL_FIRST_FOURTH |
| 87 | +void _MulleDynamicObjectNumberSetter( MulleDynamicObject *self, mulle_objc_methodid_t _cmd, void *_param, char *objcType); |
| 88 | + |
| 89 | +MULLE_C_NONNULL_FIRST |
| 90 | +void _MulleDynamicObjectValueGetter( MulleDynamicObject *self, SEL _cmd, void *_param); |
| 91 | + |
| 92 | + |
| 93 | +@interface MulleDynamicObject( NSMutableCopying)< NSMutableCopying> |
| 94 | + |
| 95 | +// we can't do NSCopying, because we are mutable, but mutableCopy is sorta |
| 96 | +// outlawed (I am so conflicted) |
| 97 | +- (id) mutableCopy; |
| 98 | + |
| 99 | +@end |
0 commit comments