Viskores  1.0
FieldCollection.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_internal_FieldCollection_h
19 #define viskores_cont_internal_FieldCollection_h
20 
21 #include <set>
22 #include <viskores/cont/Field.h>
23 
24 namespace viskores
25 {
26 namespace cont
27 {
28 namespace internal
29 {
30 
31 class VISKORES_CONT_EXPORT FieldCollection
32 {
33 public:
35  FieldCollection(std::initializer_list<viskores::cont::Field::Association> validAssoc)
36  {
37  auto it = this->ValidAssoc.begin();
38  for (const auto& item : validAssoc)
39  it = this->ValidAssoc.insert(it, item);
40  }
41 
43  FieldCollection(std::set<viskores::cont::Field::Association>&& validAssoc)
44  : ValidAssoc(std::move(validAssoc))
45  {
46  }
47 
49  void Clear() { this->Fields.clear(); }
50 
52  viskores::IdComponent GetNumberOfFields() const
53  {
54  return static_cast<viskores::IdComponent>(this->Fields.size());
55  }
56 
57  VISKORES_CONT void AddField(const Field& field);
58 
60  const viskores::cont::Field& GetField(viskores::Id index) const;
61 
63  viskores::cont::Field& GetField(viskores::Id index);
64 
66  bool HasField(
67  const std::string& name,
69  {
70  return (this->GetFieldIndex(name, assoc) != -1);
71  }
72 
74  viskores::Id GetFieldIndex(
75  const std::string& name,
77 
79  const viskores::cont::Field& GetField(
80  const std::string& name,
82 
84  viskores::cont::Field& GetField(
85  const std::string& name,
87 
88 private:
89  struct FieldCompare
90  {
91  using Key = std::pair<std::string, viskores::cont::Field::Association>;
92 
93  template <typename T>
94  bool operator()(const T& a, const T& b) const
95  {
96  if (a.first == b.first)
97  return a.second < b.second && a.second != viskores::cont::Field::Association::Any &&
99 
100  return a.first < b.first;
101  }
102  };
103 
104  std::map<FieldCompare::Key, viskores::cont::Field, FieldCompare> Fields;
105  std::set<viskores::cont::Field::Association> ValidAssoc;
106 };
107 
108 }
109 }
110 } // namespace viskores::cont::internal
111 
112 #endif //viskores_cont_internal_FieldCollection_h
viskores::cont::Field::Association
Association
Identifies what elements of a data set a field is associated with.
Definition: Field.h:46
viskores::cont::Field::Association::Any
@ Any
Any field regardless of the association.
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Field.h
viskores::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: Field.h:39