source: proiecte/HadoopJUnit/hadoop-0.20.1/src/c++/librecordio/recordTypeInfo.cc @ 141

Last change on this file since 141 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "recordTypeInfo.hh"
20
21using namespace hadoop;
22
23RecordTypeInfo::RecordTypeInfo() 
24{
25  pStid = new StructTypeID();
26}
27
28RecordTypeInfo::RecordTypeInfo(const char *pName): name(pName)
29{
30  pStid = new StructTypeID();
31}
32
33
34/*RecordTypeInfo::RecordTypeInfo(const RecordTypeInfo& rti): name(rti.name)
35{
36  // clone the typeinfos from rti and add them
37  for (unsigned int i=0; i<rti.typeInfos.size(); i++) {
38    typeInfos.push_back(rti.typeInfos[i]->clone());
39  }
40  // clone the map
41  for (std::map<std::string, RecordTypeInfo*>::const_iterator iter=rti.structRTIs.begin();
42       iter!=rti.structRTIs.end(); ++iter) {
43    structRTIs[iter->first] = iter->second->clone();
44  }
45}*/
46
47
48RecordTypeInfo::~RecordTypeInfo()
49{
50  if (NULL != pStid) 
51    delete pStid;
52
53  /*for (unsigned int i=0; i<typeInfos.size(); i++) {
54    delete typeInfos[i];
55  }
56  typeInfos.clear();
57  for (std::map<std::string, RecordTypeInfo*>::const_iterator iter=structRTIs.begin();
58       iter!=structRTIs.end(); ++iter) {
59    // delete the RTI objects
60    delete iter->second;
61  }
62  structRTIs.clear();*/
63}
64
65void RecordTypeInfo::addField(const std::string* pFieldID, const TypeID* pTypeID)
66{
67  pStid->getFieldTypeInfos().push_back(new FieldTypeInfo(pFieldID, pTypeID));
68}
69
70void RecordTypeInfo::addAll(std::vector<FieldTypeInfo*>& vec)
71{
72  // we need to copy object clones into our own vector
73  for (unsigned int i=0; i<vec.size(); i++) {
74    pStid->getFieldTypeInfos().push_back(vec[i]->clone());
75  }
76}
77
78// make a copy of typeInfos and return it
79/*std::vector<TypeInfo*>& RecordTypeInfo::getClonedTypeInfos()
80{
81  std::vector<TypeInfo*>* pNewVec = new std::vector<TypeInfo*>();
82  for (unsigned int i=0; i<typeInfos.size(); i++) {
83    pNewVec->push_back(typeInfos[i]->clone());
84  }
85  return *pNewVec;
86} */
87
88const std::vector<FieldTypeInfo*>& RecordTypeInfo::getFieldTypeInfos() const
89{
90  return pStid->getFieldTypeInfos();
91}
92
93
94RecordTypeInfo* RecordTypeInfo::getNestedStructTypeInfo(const char *structName) const
95{
96  StructTypeID* p = pStid->findStruct(structName);
97  if (NULL == p) return NULL;
98  return new RecordTypeInfo(structName, p);
99  /*std::string s(structName);
100  std::map<std::string, RecordTypeInfo*>::const_iterator iter = structRTIs.find(s);
101  if (iter == structRTIs.end()) {
102    return NULL;
103  }
104  return iter->second;*/
105}
106
107void RecordTypeInfo::serialize(::hadoop::OArchive& a_, const char* tag) const
108{
109  a_.startRecord(*this, tag);
110  // name
111  a_.serialize(name, tag);
112  /*// number of elements
113  a_.serialize((int32_t)typeInfos.size(), tag);
114  // write out each element
115  for (std::vector<FieldTypeInfo*>::const_iterator iter=typeInfos.begin();
116       iter!=typeInfos.end(); ++iter) {
117    (*iter)->serialize(a_, tag);
118    }*/
119  pStid->serializeRest(a_, tag);
120  a_.endRecord(*this, tag);
121}
122
123void RecordTypeInfo::print(int space) const
124{
125  for (int i=0; i<space; i++) {
126    printf(" ");
127  }
128  printf("RecordTypeInfo::%s\n", name.c_str());
129  pStid->print(space);
130  /*for (unsigned i=0; i<typeInfos.size(); i++) {
131    typeInfos[i]->print(space+2);
132    }*/
133}
134
135void RecordTypeInfo::deserialize(::hadoop::IArchive& a_, const char* tag)
136{
137  a_.startRecord(*this, tag);
138  // name
139  a_.deserialize(name, tag);
140  pStid->deserialize(a_, tag);
141  a_.endRecord(*this, tag);
142}
143
Note: See TracBrowser for help on using the repository browser.