1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "FunctionID.h" 8 9 #include <new> 10 11 #include <Message.h> 12 13 14 // #pragma mark - FunctionID 15 16 17 FunctionID::FunctionID(const BMessage& archive) 18 : 19 BArchivable(const_cast<BMessage*>(&archive)) 20 { 21 archive.FindString("FunctionID::path", &fPath); 22 archive.FindString("FunctionID::functionName", &fFunctionName); 23 } 24 25 26 FunctionID::FunctionID(const BString& path, const BString& functionName) 27 : 28 fPath(path), 29 fFunctionName(functionName) 30 { 31 } 32 33 34 FunctionID::~FunctionID() 35 { 36 } 37 38 39 status_t 40 FunctionID::Archive(BMessage* archive, bool deep) const 41 { 42 status_t error = BArchivable::Archive(archive, deep); 43 if (error != B_OK) 44 return error; 45 46 error = archive->AddString("FunctionID::path", fPath); 47 if (error == B_OK) 48 error = archive->AddString("FunctionID::functionName", fFunctionName); 49 return error; 50 } 51 52 53 uint32 54 FunctionID::ComputeHashValue() const 55 { 56 return fPath.HashValue() * 17 57 + fFunctionName.HashValue(); 58 } 59 60 61 bool 62 FunctionID::IsValid() const 63 { 64 return fPath.Length() != 0 && fFunctionName.Length() != 0; 65 } 66 67 68 // #pragma mark - SourceFunctionID 69 70 71 SourceFunctionID::SourceFunctionID(const BMessage& archive) 72 : 73 FunctionID(archive) 74 { 75 } 76 77 78 SourceFunctionID::SourceFunctionID(const BString& sourceFilePath, 79 const BString& functionName) 80 : 81 FunctionID(sourceFilePath, functionName) 82 { 83 } 84 85 86 SourceFunctionID::~SourceFunctionID() 87 { 88 } 89 90 91 /*static*/ BArchivable* 92 SourceFunctionID::Instantiate(BMessage* archive) 93 { 94 if (archive == NULL) 95 return NULL; 96 97 SourceFunctionID* object = new(std::nothrow) SourceFunctionID(*archive); 98 if (object == NULL) 99 return NULL; 100 101 if (!object->IsValid()) { 102 delete object; 103 return NULL; 104 } 105 106 return object; 107 } 108 109 110 bool 111 SourceFunctionID::operator==(const ObjectID& _other) const 112 { 113 const SourceFunctionID* other = dynamic_cast<const SourceFunctionID*>( 114 &_other); 115 return other != NULL && fPath == other->fPath 116 && fFunctionName == other->fFunctionName; 117 } 118 119 120 // #pragma mark - ImageFunctionID 121 122 123 ImageFunctionID::ImageFunctionID(const BMessage& archive) 124 : 125 FunctionID(archive) 126 { 127 } 128 129 130 ImageFunctionID::ImageFunctionID(const BString& imageName, 131 const BString& functionName) 132 : 133 FunctionID(imageName, functionName) 134 { 135 } 136 137 138 ImageFunctionID::~ImageFunctionID() 139 { 140 } 141 142 143 /*static*/ BArchivable* 144 ImageFunctionID::Instantiate(BMessage* archive) 145 { 146 if (archive == NULL) 147 return NULL; 148 149 ImageFunctionID* object = new(std::nothrow) ImageFunctionID(*archive); 150 if (object == NULL) 151 return NULL; 152 153 if (!object->IsValid()) { 154 delete object; 155 return NULL; 156 } 157 158 return object; 159 } 160 161 162 bool 163 ImageFunctionID::operator==(const ObjectID& _other) const 164 { 165 const ImageFunctionID* other = dynamic_cast<const ImageFunctionID*>( 166 &_other); 167 return other != NULL && fPath == other->fPath 168 && fFunctionName == other->fFunctionName; 169 } 170