1 /*
2   Copyright (c) DataStax, 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 
17 #ifndef DATASTAX_INTERNAL_RESULT_METADATA_HPP
18 #define DATASTAX_INTERNAL_RESULT_METADATA_HPP
19 
20 #include "cassandra.h"
21 #include "data_type.hpp"
22 #include "hash_table.hpp"
23 #include "ref_counted.hpp"
24 #include "string_ref.hpp"
25 
26 #include <uv.h>
27 
28 #include <algorithm>
29 
30 namespace datastax { namespace internal { namespace core {
31 
32 struct ColumnDefinition : public HashTableEntry<ColumnDefinition> {
33   StringRef name;
34   StringRef keyspace;
35   StringRef table;
36   DataType::ConstPtr data_type;
37 };
38 
39 class ResultMetadata : public RefCounted<ResultMetadata> {
40 public:
41   typedef SharedRefPtr<ResultMetadata> Ptr;
42 
43   ResultMetadata(size_t column_count, const RefBuffer::Ptr& buffer);
44 
get_column_definition(size_t index) const45   const ColumnDefinition& get_column_definition(size_t index) const { return defs_[index]; }
46 
47   size_t get_indices(StringRef name, IndexVec* result) const;
48 
column_count() const49   size_t column_count() const { return defs_.size(); }
50 
51   void add(const ColumnDefinition& meta);
52 
53 private:
54   CaseInsensitiveHashTable<ColumnDefinition> defs_;
55   RefBuffer::Ptr buffer_;
56 
57 private:
58   DISALLOW_COPY_AND_ASSIGN(ResultMetadata);
59 };
60 
61 }}} // namespace datastax::internal::core
62 
63 #endif
64