lsst.afw  14.0-38-g278b05818
arrays.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2014 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef AFW_TABLE_arrays_h_INCLUDED
24 #define AFW_TABLE_arrays_h_INCLUDED
25 
27 #include "lsst/afw/table/Schema.h"
28 
29 namespace lsst {
30 namespace afw {
31 namespace table {
32 
40 template <typename T>
41 class ArrayKey : public FunctorKey<ndarray::Array<T const, 1, 1> >,
42  public ReferenceFunctorKey<ndarray::ArrayRef<T, 1, 1> >,
43  public ConstReferenceFunctorKey<ndarray::ArrayRef<T const, 1, 1> > {
44 public:
59  static ArrayKey addFields(Schema& schema, std::string const& name, std::string const& doc,
60  std::string const& unit, std::vector<T> const& docData);
61 
72  static ArrayKey addFields(Schema& schema, std::string const& name, std::string const& doc,
73  std::string const& unit, int size);
74 
76  ArrayKey() : _begin() {}
77 
79  explicit ArrayKey(std::vector<Key<T> > const& keys);
80 
87  explicit ArrayKey(Key<Array<T> > const& other);
88 
97  ArrayKey(SubSchema const& s);
98 
100  int getSize() const { return _size; }
101 
103  virtual ndarray::Array<T const, 1, 1> get(BaseRecord const& record) const;
104 
106  virtual void set(BaseRecord& record, ndarray::Array<T const, 1, 1> const& value) const;
107 
109  virtual ndarray::ArrayRef<T, 1, 1> getReference(BaseRecord& record) const;
110 
112  virtual ndarray::ArrayRef<T const, 1, 1> getConstReference(BaseRecord const& record) const;
113 
115  bool operator==(ArrayKey<T> const& other) const { return other._begin == _begin && other._size == _size; }
117  bool operator!=(ArrayKey<T> const& other) const { return !operator==(other); }
119 
121  bool isValid() const { return _begin.isValid(); }
122 
124  Key<T> operator[](int i) const;
125 
127  ArrayKey slice(int begin, int end) const;
128 
129 private:
130  ArrayKey(Key<T> const& begin, int size) : _begin(begin), _size(size) {}
131 
132  Key<T> _begin;
133  int _size;
134 };
135 }
136 }
137 } // namespace lsst::afw::table
138 
139 #endif // !AFW_TABLE_arrays_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:47
A FunctorKey used to get or set a ndarray::Array from a sequence of scalar Keys.
Definition: arrays.h:41
bool operator!=(ArrayKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition: arrays.h:117
A proxy type for name lookups in a Schema.
Definition: Schema.h:349
static ArrayKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit, std::vector< T > const &docData)
Add an array of fields to a Schema, and return an ArrayKey that points to them.
table::Key< std::string > name
Definition: ApCorrMap.cc:71
afw::table::Schema schema
Definition: GaussianPsf.cc:43
bool isValid() const
Return True if the FunctorKey contains valid scalar keys.
Definition: arrays.h:121
bool operator==(ArrayKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition: arrays.h:116
virtual ndarray::ArrayRef< T, 1, 1 > getReference(BaseRecord &record) const
Get non-const reference array from the given record.
STL class.
A base class for image defects.
int end
Base class for objects that can return a const reference to part of a record, but are not a true Key...
Definition: FunctorKey.h:99
Key< T > operator[](int i) const
Return a scalar Key for an element of the array.
Tag types used to declare specialized field types.
Definition: misc.h:32
ArrayKey slice(int begin, int end) const
Return a FunctorKey corresponding to a range of elements.
int getSize() const
Return the number of elements in the array.
Definition: arrays.h:100
Base class for objects that can return a non-const reference to part of a record, but are not a true ...
Definition: FunctorKey.h:81
STL class.
Base class for all records.
Definition: BaseRecord.h:29
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
virtual ndarray::ArrayRef< T const, 1, 1 > getConstReference(BaseRecord const &record) const
Get const reference array from the given record.
ArrayKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
Definition: arrays.h:76
Convenience base class that combines the OutputFunctorKey and InputFunctorKey.
Definition: FunctorKey.h:68