1/* 2 * Copyright 2010, Rene Gollent, rene@gollent.com 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7#include "CStringTypeHandler.h" 8 9#include <new> 10 11#include <stdio.h> 12 13#include "CStringValueNode.h" 14#include "Type.h" 15 16 17CStringTypeHandler::~CStringTypeHandler() 18{ 19} 20 21 22float 23CStringTypeHandler::SupportsType(Type* type) 24{ 25 AddressType* addressType = dynamic_cast<AddressType*>(type); 26 ArrayType* arrayType = dynamic_cast<ArrayType*>(type); 27 PrimitiveType* baseType = NULL; 28 ModifiedType* modifiedType = NULL; 29 if (addressType != NULL && addressType->AddressKind() 30 == DERIVED_TYPE_POINTER) { 31 baseType = dynamic_cast<PrimitiveType*>( 32 addressType->BaseType()); 33 if (baseType == NULL) { 34 modifiedType = dynamic_cast<ModifiedType*>( 35 addressType->BaseType()); 36 } 37 } else if (arrayType != NULL && arrayType->CountDimensions() == 1) { 38 baseType = dynamic_cast<PrimitiveType*>( 39 arrayType->BaseType()); 40 if (baseType == NULL) { 41 modifiedType = dynamic_cast<ModifiedType*>( 42 arrayType->BaseType()); 43 } 44 } 45 46 if (baseType == NULL && modifiedType == NULL) 47 return 0.0f; 48 else if (modifiedType != NULL) { 49 baseType = dynamic_cast<PrimitiveType*>( 50 modifiedType->ResolveRawType(false)); 51 if (baseType == NULL) 52 return 0.0f; 53 } 54 55 if (baseType->TypeConstant() == B_UINT8_TYPE 56 || baseType->TypeConstant() == B_INT8_TYPE) 57 return 0.8f; 58 59 return 0.0f; 60} 61 62 63status_t 64CStringTypeHandler::CreateValueNode(ValueNodeChild* nodeChild, Type* type, 65 ValueNode*& _node) 66{ 67 if (SupportsType(type) == 0.0f) 68 return B_BAD_VALUE; 69 70 ValueNode* node = new(std::nothrow) CStringValueNode(nodeChild, 71 type); 72 73 if (node == NULL) 74 return B_NO_MEMORY; 75 76 _node = node; 77 78 return B_OK; 79} 80