]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_transform/lib/CoreFoundationBasics.h
Security-59306.101.1.tar.gz
[apple/security.git] / OSX / libsecurity_transform / lib / CoreFoundationBasics.h
1 #ifndef __CORE_FOUNDATION_BASICS__
2 #define __CORE_FOUNDATION_BASICS__
3
4
5
6 /*
7 This file contains basics for supporting our objects as CoreFoundation
8 objects.
9 */
10
11 #include <CoreFoundation/CFRuntime.h>
12 #include <string>
13 #include "LinkedList.h"
14
15 void CoreFoundationObjectsRegister();
16
17 extern const CFStringRef gInternalCFObjectName;
18 extern const CFStringRef gInternalProtectedCFObjectName;
19
20 struct CoreFoundationHolder;
21
22 class CoreFoundationObject
23 {
24 private:
25 CoreFoundationHolder* mHolder;
26
27 protected:
28 CoreFoundationObject(CFStringRef objectType);
29
30 protected:
31 CFStringRef mObjectType;
32
33 public:
34 virtual ~CoreFoundationObject();
35
36 // compares mHolder's pointer, if you override you need
37 // to also override Hash.
38 virtual Boolean Equal(const CoreFoundationObject* object);
39 virtual CFHashCode Hash();
40 virtual std::string FormattingDescription(CFDictionaryRef options);
41 virtual std::string DebugDescription();
42 // default is to call delete. Complex objects with queues may wish to release the queue and use the queue finalizer to call delete.
43 virtual void Finalize();
44
45 // register your class with the CFRuntime. You must supply
46 // a class name for your object.
47 static void RegisterObject(CFStringRef name, bool protectFromDelete);
48 static CFTypeID FindObjectType(CFStringRef name);
49 static LinkedListHeader* GetClassRegistryList();
50
51 void SetHolder(CoreFoundationHolder* holder) {mHolder = holder;}
52 CFTypeRef GetCFObject() {return mHolder;}
53
54 CFStringRef GetTypeAsCFString();
55 };
56
57
58
59 struct CoreFoundationHolder
60 {
61 CFRuntimeBase mRuntimeBase;
62 CoreFoundationObject* mObject;
63 // name should really be a CFStringRef, not std::string (better memory use)
64 static CoreFoundationHolder* MakeHolder(CFStringRef name, CoreFoundationObject* object);
65 static CoreFoundationObject* ObjectFromCFType(CFTypeRef cfRef);
66 };
67
68
69
70 #endif