OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
fieldcomposite.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef CMZN_FIELDCOMPOSITE_HPP__
10 #define CMZN_FIELDCOMPOSITE_HPP__
11 
12 
13 #include "zinc/fieldcomposite.h"
14 #include "zinc/field.hpp"
15 #include "zinc/fieldmodule.hpp"
16 
17 namespace OpenCMISS
18 {
19 namespace Zinc
20 {
21 class FieldIdentity : public Field
31 {
32 
33 private:
34  // takes ownership of C handle, responsibility for destroying it
35  explicit FieldIdentity(cmzn_field_id field_id) : Field(field_id)
36  { }
37 
38  friend FieldIdentity Fieldmodule::createFieldIdentity(const Field& sourceField);
39 
40 public:
41 
42  FieldIdentity() : Field(0)
43  { }
44 
45 };
46 
52 class FieldComponent : public Field
53 {
54 public:
55 
56  FieldComponent() : Field(0)
57  { }
58 
59  // takes ownership of C handle, responsibility for destroying it
60  explicit FieldComponent(cmzn_field_component_id field_component_id) :
61  Field(reinterpret_cast<cmzn_field_id>(field_component_id))
62  { }
63 
69  inline cmzn_field_component_id getDerivedId()
70  {
71  return reinterpret_cast<cmzn_field_component_id>(id);
72  }
73 
80  {
81  return cmzn_field_component_get_component_index(getDerivedId());
82  }
83 
89  int setComponentIndex(int componentIndex)
90  {
91  return cmzn_field_component_set_component_index(getDerivedId(), componentIndex);
92  }
93 
94 };
95 class FieldConcatenate : public Field
104 {
105 private:
106 
107  // takes ownership of C handle, responsibility for destroying it
108  explicit FieldConcatenate(cmzn_field_id field_id) : Field(field_id)
109  { }
110 
111  friend FieldConcatenate Fieldmodule::createFieldConcatenate(int fieldsCount, const Field *sourceFields);
112 
113 public:
114 
115  FieldConcatenate() : Field(0)
116  { }
117 
118 };
119 
121 {
122  return FieldIdentity(cmzn_fieldmodule_create_field_identity(id, sourceField.getId()));
123 }
124 
125 inline FieldComponent Fieldmodule::createFieldComponent(const Field& sourceField, int componentIndex)
126 {
127  return FieldComponent(reinterpret_cast<cmzn_field_component_id>(
128  cmzn_fieldmodule_create_field_component(id, sourceField.getId(), componentIndex)));
129 }
130 
132 {
133  return FieldComponent(cmzn_field_cast_component(id));
134 }
135 
136 inline FieldConcatenate Fieldmodule::createFieldConcatenate(int fieldsCount, const Field *sourceFields)
137 {
138  cmzn_field_id concatenateField = 0;
139  if (fieldsCount > 0)
140  {
141  cmzn_field_id *source_fields = new cmzn_field_id[fieldsCount];
142  for (int i = 0; i < fieldsCount; i++)
143  {
144  source_fields[i] = sourceFields[i].getId();
145  }
146  concatenateField = cmzn_fieldmodule_create_field_concatenate(id, fieldsCount, source_fields);
147  delete[] source_fields;
148  }
149  return FieldConcatenate(concatenateField);
150 }
151 
152 } // namespace Zinc
153 }
154 
155 #endif
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
A field which concatenates the components of all source fields, in order, into a single vector...
Definition: fieldcomposite.hpp:103
FieldComponent createFieldComponent(const Field &sourceField, int componentIndex)
Definition: fieldcomposite.hpp:125
FieldComponent castComponent()
Definition: fieldcomposite.hpp:131
A field returning a single component of a source field as a scalar.
Definition: fieldcomposite.hpp:52
cmzn_field_id getId() const
Definition: field.hpp:98
int getComponentIndex()
Definition: fieldcomposite.hpp:79
cmzn_field_component_id getDerivedId()
Definition: fieldcomposite.hpp:69
int setComponentIndex(int componentIndex)
Definition: fieldcomposite.hpp:89
FieldConcatenate createFieldConcatenate(int fieldsCount, const Field *sourceFields)
Definition: fieldcomposite.hpp:136
FieldIdentity createFieldIdentity(const Field &sourceField)
Definition: fieldcomposite.hpp:120
A field with the single source field.
Definition: fieldcomposite.hpp:30