Line data Source code
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, 13 : * software distributed under the License is distributed on an 14 : * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 : * KIND, either express or implied. See the License for the 16 : * specific language governing permissions and limitations 17 : * under the License. 18 : * 19 : * Copyright 2006-2017 The Apache Software Foundation. 20 : * https://github.com/apache/thrift 21 : * 22 : * Modifications Copyright (c) Juniper Networks, Inc. 23 : * Copyright Contributors to the OpenSDN project 24 : */ 25 : 26 : #ifndef T_SANDESH_H 27 : #define T_SANDESH_H 28 : 29 : #include <string> 30 : 31 : #include "t_type.h" 32 : #include "t_struct_common.h" 33 : #include "t_base_type.h" 34 : 35 : // Forward declare that puppy 36 : class t_program; 37 : 38 : /** 39 : * A sandesh is a container for a set of member fields that has a name. 40 : * 41 : */ 42 : class t_sandesh : public t_struct_common { 43 : public: 44 11608 : t_sandesh(t_program* program) : 45 : t_struct_common(program), 46 11608 : type_(NULL) {} 47 : 48 : t_sandesh(t_program* program, const std::string& name) : 49 : t_struct_common(program, name), 50 : type_(NULL) {} 51 : 52 4666 : virtual std::string get_struct_type_name() { 53 4666 : return "Sandesh"; 54 : } 55 : 56 698 : virtual bool is_sandesh() const { 57 698 : return true; 58 : } 59 : 60 11608 : void set_type(t_type* type) { 61 11608 : type_ = type; 62 11608 : } 63 : 64 5408 : bool exist_opt_field() { 65 5408 : members_type::const_iterator m_iter; 66 28146 : for (m_iter = members_in_id_order_.begin(); m_iter != members_in_id_order_.end(); ++m_iter) { 67 22738 : if ((*m_iter)->get_req() == t_field::T_OPTIONAL) { 68 0 : return true; 69 : } 70 : } 71 5408 : return false; 72 : } 73 : 74 81760 : const t_type* get_type() { 75 81760 : return type_; 76 : } 77 : 78 7535 : bool is_level_category_supported() const { 79 7535 : t_base_type *btype = (t_base_type *) type_; 80 17365 : return btype->is_sandesh_system() || btype->is_sandesh_object() || 81 17365 : btype->is_sandesh_flow() || btype->is_sandesh_uve(); 82 : } 83 : 84 : virtual bool has_key_annotation() const; 85 : 86 : private: 87 : t_type* type_; 88 : }; 89 : 90 : #endif