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 | package org.apache.hadoop.record.compiler; |
---|
20 | |
---|
21 | |
---|
22 | /** |
---|
23 | * Abstract base class for all the "compound" types such as ustring, |
---|
24 | * buffer, vector, map, and record. |
---|
25 | */ |
---|
26 | abstract class JCompType extends JType { |
---|
27 | |
---|
28 | abstract class JavaCompType extends JavaType { |
---|
29 | |
---|
30 | JavaCompType(String type, String suffix, String wrapper, |
---|
31 | String typeIDByteString) { |
---|
32 | super(type, suffix, wrapper, typeIDByteString); |
---|
33 | } |
---|
34 | |
---|
35 | void genCompareTo(CodeBuffer cb, String fname, String other) { |
---|
36 | cb.append(Consts.RIO_PREFIX + "ret = "+fname+".compareTo("+other+");\n"); |
---|
37 | } |
---|
38 | |
---|
39 | void genEquals(CodeBuffer cb, String fname, String peer) { |
---|
40 | cb.append(Consts.RIO_PREFIX + "ret = "+fname+".equals("+peer+");\n"); |
---|
41 | } |
---|
42 | |
---|
43 | void genHashCode(CodeBuffer cb, String fname) { |
---|
44 | cb.append(Consts.RIO_PREFIX + "ret = "+fname+".hashCode();\n"); |
---|
45 | } |
---|
46 | |
---|
47 | void genClone(CodeBuffer cb, String fname) { |
---|
48 | cb.append(Consts.RIO_PREFIX + "other."+fname+" = ("+getType()+") this."+ |
---|
49 | fname+".clone();\n"); |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | abstract class CppCompType extends CppType { |
---|
54 | |
---|
55 | CppCompType(String type) { |
---|
56 | super(type); |
---|
57 | } |
---|
58 | |
---|
59 | void genGetSet(CodeBuffer cb, String fname) { |
---|
60 | cb.append("virtual const "+getType()+"& get"+toCamelCase(fname)+"() const {\n"); |
---|
61 | cb.append("return "+fname+";\n"); |
---|
62 | cb.append("}\n"); |
---|
63 | cb.append("virtual "+getType()+"& get"+toCamelCase(fname)+"() {\n"); |
---|
64 | cb.append("return "+fname+";\n"); |
---|
65 | cb.append("}\n"); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | class CCompType extends CType { |
---|
70 | |
---|
71 | } |
---|
72 | } |
---|