/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "typeIDs.hh" using namespace hadoop; void TypeID::serialize(::hadoop::OArchive& a_, const char* tag) const { a_.serialize(typeVal, tag); } bool TypeID::operator==(const TypeID& peer_) const { return (this->typeVal == peer_.typeVal); } void TypeID::print(int space) const { for (int i=0; ipName = p; }*/ StructTypeID::StructTypeID(const std::vector& vec) : TypeID(RIOTYPE_STRUCT) { // we need to copy object clones into our own vector for (unsigned int i=0; iclone()); } } /*StructTypeID::StructTypeID(const StructTypeID& ti) : TypeID(RIOTYPE_STRUCT) { // we need to copy object clones into our own vector for (unsigned int i=0; iclone()); } } */ StructTypeID::~StructTypeID() { for (unsigned int i=0; igetFieldID()->compare(pStructName)) && (typeInfos[i]->getTypeID()->getTypeVal()==RIOTYPE_STRUCT)) { return (StructTypeID*)(typeInfos[i]->getTypeID()->clone()); } } return NULL; } void StructTypeID::serialize(::hadoop::OArchive& a_, const char* tag) const { a_.serialize(typeVal, tag); serializeRest(a_, tag); } /* * Writes rest of the struct (excluding type value). * As an optimization, this method is directly called by RTI * for the top level record so that we don't write out the byte * indicating that this is a struct (since top level records are * always structs). */ void StructTypeID::serializeRest(::hadoop::OArchive& a_, const char* tag) const { a_.serialize((int32_t)typeInfos.size(), tag); for (unsigned int i=0; iserialize(a_, tag); } } /* * deserialize ourselves. Called by RTI. */ void StructTypeID::deserialize(::hadoop::IArchive& a_, const char* tag) { // number of elements int numElems; a_.deserialize(numElems, tag); for (int i=0; iadd(genericReadTypeInfo(a_, tag)); } return pstID; } case RIOTYPE_VECTOR: { TypeID* pti = genericReadTypeID(a_, tag); return new VectorTypeID(pti); } case RIOTYPE_MAP: { TypeID* ptiKey = genericReadTypeID(a_, tag); TypeID* ptiValue = genericReadTypeID(a_, tag); return new MapTypeID(ptiKey, ptiValue); } default: // shouldn't be here return NULL; } } void StructTypeID::print(int space) const { TypeID::print(space); for (int i=0; iprint(space+2); } } VectorTypeID::~VectorTypeID() { delete ptiElement; } VectorTypeID::VectorTypeID(const VectorTypeID& ti): TypeID(RIOTYPE_VECTOR) { ptiElement = ti.ptiElement->clone(); } void VectorTypeID::serialize(::hadoop::OArchive& a_, const char* tag) const { a_.serialize(typeVal, tag); ptiElement->serialize(a_, tag); } bool VectorTypeID::operator==(const TypeID& peer_) const { if (typeVal != peer_.getTypeVal()) { return false; } // this must be a vector type id return (*ptiElement) == (*((VectorTypeID&)peer_).ptiElement); } void VectorTypeID::print(int space) const { TypeID::print(space); for (int i=0; iprint(space+2); } MapTypeID::~MapTypeID() { delete ptiKey; delete ptiValue; } MapTypeID::MapTypeID(const MapTypeID& ti): TypeID(RIOTYPE_MAP) { ptiKey = ti.ptiKey->clone(); ptiValue = ti.ptiValue->clone(); } void MapTypeID::serialize(::hadoop::OArchive& a_, const char* tag) const { a_.serialize(typeVal, tag); ptiKey->serialize(a_, tag); ptiValue->serialize(a_, tag); } bool MapTypeID::operator==(const TypeID& peer_) const { if (typeVal != peer_.getTypeVal()) { return false; } // this must be a map type id MapTypeID& mti = (MapTypeID&) peer_; if (!(*ptiKey == *(mti.ptiKey))) { return false; } return ((*ptiValue == *(mti.ptiValue))); } void MapTypeID::print(int space) const { TypeID::print(space); for (int i=0; iprint(space+2); ptiValue->print(space+2); }