OmniSciDB  04ee39c94c
ExtensionFunction.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.mapd.parser.server;
17 
18 import java.util.ArrayList;
19 import java.util.List;
20 
25 public class ExtensionFunction {
26  public enum ExtArgumentType {
41  }
42  ;
43 
44  ExtensionFunction(final List<ExtArgumentType> args, final ExtArgumentType ret) {
45  this.args = args;
46  this.ret = ret;
47  }
48 
49  public List<ExtArgumentType> getArgs() {
50  return this.args;
51  }
52 
54  return this.ret;
55  }
56 
57  public String toJson(final String name) {
58  StringBuilder json_cons = new StringBuilder();
59  json_cons.append("{");
60  json_cons.append("\"name\":").append(dq(name)).append(",");
61  json_cons.append("\"ret\":").append(dq(typeName(ret))).append(",");
62  json_cons.append("\"args\":");
63  json_cons.append("[");
64  List<String> param_list = new ArrayList<String>();
65  for (final ExtArgumentType arg : args) {
66  param_list.add(dq(typeName(arg)));
67  }
68  json_cons.append(ExtensionFunctionSignatureParser.join(param_list, ","));
69  json_cons.append("]");
70  json_cons.append("}");
71  return json_cons.toString();
72  }
73 
74  private static String typeName(final ExtArgumentType type) {
75  switch (type) {
76  case Bool:
77  return "i1";
78  case Int8:
79  return "i8";
80  case Int16:
81  return "i16";
82  case Int32:
83  return "i32";
84  case Int64:
85  return "i64";
86  case Float:
87  return "float";
88  case Double:
89  return "double";
90  case PInt8:
91  return "i8*";
92  case PInt16:
93  return "i16*";
94  case PInt32:
95  return "i32*";
96  case PInt64:
97  return "i64*";
98  case PFloat:
99  return "float*";
100  case PDouble:
101  return "double*";
102  }
103  assert false;
104  return null;
105  }
106 
107  private static String dq(final String str) {
108  return "\"" + str + "\"";
109  }
110 
111  private final List<ExtArgumentType> args;
112  private final ExtArgumentType ret;
113 }
ExtensionFunction(final List< ExtArgumentType > args, final ExtArgumentType ret)
static String typeName(final ExtArgumentType type)
static String join(final List< String > strs, final String sep)
static String dq(final String str)