1 /* 2 * Copyright (c) Facebook, Inc. and its affiliates. 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 17 #pragma once 18 19 #include <thrift/compiler/ast/t_container.h> 20 #include <thrift/compiler/ast/t_type.h> 21 22 namespace apache { 23 namespace thrift { 24 namespace compiler { 25 26 /** 27 * A list is a lightweight container type that just wraps another data type. 28 * 29 */ 30 class t_list final : public t_container { 31 public: t_list(t_type_ref elem_type)32 explicit t_list(t_type_ref elem_type) : elem_type_(std::move(elem_type)) {} 33 elem_type()34 const t_type_ref& elem_type() const { return elem_type_; } 35 container_type()36 type container_type() const override { return type::t_list; } get_full_name()37 std::string get_full_name() const override { 38 return "list<" + elem_type_->get_full_name() + ">"; 39 } 40 41 private: 42 t_type_ref elem_type_; 43 44 // TODO(afuller): Delete everything below here. It is only provided for 45 // backwards compatibility. 46 public: t_list(const t_type * elem_type)47 explicit t_list(const t_type* elem_type) 48 : t_list(t_type_ref::from_req_ptr(elem_type)) {} get_elem_type()49 const t_type* get_elem_type() const { return elem_type().get_type(); } 50 }; 51 52 } // namespace compiler 53 } // namespace thrift 54 } // namespace apache 55