1 /* 2 Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 #ifndef NdbInfoRecAttr_H 26 #define NdbInfoRecAttr_H 27 28 class NdbInfoRecAttr { 29 public: ptr() const30 const void* ptr() const { 31 assert(m_requested); 32 return m_data; 33 } 34 u_32_value() const35 Uint32 u_32_value() const { 36 assert(m_requested); 37 assert(m_len == sizeof(Uint32)); 38 return *((const Uint32 *) m_data); 39 } 40 u_64_value() const41 Uint64 u_64_value() const { 42 Uint64 val; 43 assert(m_requested); 44 assert(m_len == sizeof(Uint64)); 45 memcpy(&val, m_data, sizeof(Uint64)); 46 return val; 47 } 48 c_str() const49 const char* c_str() const { 50 assert(m_requested); 51 assert(m_len > 0); 52 return m_data; 53 } 54 length() const55 Uint32 length() const { 56 assert(m_requested); 57 return m_len; 58 } 59 isNULL() const60 bool isNULL() const { 61 assert(m_requested); 62 return !m_defined; 63 } 64 65 private: 66 friend class NdbInfoRecAttrCollection; NdbInfoRecAttr()67 NdbInfoRecAttr() : 68 m_data(NULL), 69 m_len(0), 70 m_defined(false), 71 m_requested(false) 72 {} ~NdbInfoRecAttr()73 ~NdbInfoRecAttr() 74 {} 75 76 const char* m_data; 77 Uint32 m_len; 78 bool m_defined; 79 bool m_requested; 80 }; 81 82 83 // Fixed size collection of NdbInfoRecAttr 84 class NdbInfoRecAttrCollection { 85 public: 86 NdbInfoRecAttrCollection(); // Not implemented 87 NdbInfoRecAttrCollection(const NdbInfoRecAttrCollection&); // Not implemented 88 NdbInfoRecAttrCollection(unsigned count)89 NdbInfoRecAttrCollection(unsigned count) : 90 m_attr_count(count) 91 { 92 m_attrs = new NdbInfoRecAttr[count]; 93 } 94 ~NdbInfoRecAttrCollection()95 ~NdbInfoRecAttrCollection() 96 { 97 delete[] m_attrs; 98 } 99 get_value(unsigned idx)100 const NdbInfoRecAttr* get_value(unsigned idx) 101 { 102 assert(idx < m_attr_count); 103 NdbInfoRecAttr* attr = &m_attrs[idx]; 104 attr->m_requested = true; 105 return attr; 106 } 107 is_requested(unsigned idx) const108 bool is_requested(unsigned idx) const 109 { 110 assert(idx < m_attr_count); 111 return m_attrs[idx].m_requested; 112 } 113 set_recattr(unsigned idx,const char * data,Uint32 len) const114 void set_recattr(unsigned idx, 115 const char* data, 116 Uint32 len) const 117 { 118 assert(idx < m_attr_count); 119 NdbInfoRecAttr* attr = &m_attrs[idx]; 120 121 attr->m_data = data; 122 attr->m_len = len; 123 attr->m_defined = true; 124 } 125 reset_recattrs(void) const126 void reset_recattrs(void) const 127 { 128 for (unsigned i = 0; i < m_attr_count; i++) 129 { 130 m_attrs[i].m_defined = false; 131 } 132 } 133 134 private: 135 const unsigned m_attr_count; 136 NdbInfoRecAttr* m_attrs; 137 }; 138 139 #endif 140