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