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 : * Modifications Copyright (c) Juniper Networks, Inc. 20 : * Copyright Contributors to the OpenSDN project 21 : */ 22 : 23 : #ifndef T_STRUCT_H 24 : #define T_STRUCT_H 25 : 26 : #include <string> 27 : 28 : #include "t_type.h" 29 : #include "t_struct_common.h" 30 : #include "t_base_type.h" 31 : 32 : // Forward declare that puppy 33 : class t_program; 34 : 35 : /** 36 : * A struct is a container for a set of member fields that has a name. Structs 37 : * are also used to implement exception types. 38 : * 39 : */ 40 : class t_struct : public t_struct_common { 41 : public: 42 15098 : t_struct(t_program* program) : 43 : t_struct_common(program), 44 15098 : is_xception_(false), 45 15098 : xsd_all_(false) {} 46 : 47 0 : t_struct(t_program* program, const std::string& name) : 48 : t_struct_common(program, name), 49 0 : is_xception_(false), 50 0 : xsd_all_(false) {} 51 : 52 2202 : virtual std::string get_struct_type_name() { 53 2202 : return "Struct"; 54 : } 55 : 56 0 : void set_xception(bool is_xception) { 57 0 : is_xception_ = is_xception; 58 0 : } 59 : 60 9048 : void set_union(bool is_union) { 61 9048 : is_union_ = is_union; 62 9048 : } 63 : 64 9048 : void set_xsd_all(bool xsd_all) { 65 9048 : xsd_all_ = xsd_all; 66 9048 : } 67 : 68 0 : bool get_xsd_all() const { 69 0 : return xsd_all_; 70 : } 71 : 72 28851 : bool is_struct() const { 73 28851 : return !is_xception_; 74 : } 75 : 76 1700 : bool is_xception() const { 77 1700 : return is_xception_; 78 : } 79 : 80 : bool is_union() const { 81 : return is_union_; 82 : } 83 : 84 15860 : t_field* get_field_by_name(std::string field_name) { 85 15860 : members_type::const_iterator m_iter; 86 35240 : for (m_iter = members_in_id_order_.begin(); m_iter != members_in_id_order_.end(); ++m_iter) { 87 35240 : if ((*m_iter)->get_name() == field_name) { 88 15860 : return *m_iter; 89 : } 90 : } 91 0 : return NULL; 92 : } 93 : 94 : #ifdef SANDESH 95 : virtual bool has_key_annotation() const; 96 : #endif 97 : 98 : private: 99 : bool is_xception_; 100 : bool is_union_; 101 : bool xsd_all_; 102 : }; 103 : 104 : #endif