LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
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 { namespace afw { namespace table {
30 
38 template <typename T>
39 class ArrayKey : public FunctorKey< ndarray::Array<T const,1,1> >,
40  public ReferenceFunctorKey< ndarray::ArrayRef<T,1,1> >,
41  public ConstReferenceFunctorKey< ndarray::ArrayRef<T const,1,1> >
42 {
43 public:
44 
59  static ArrayKey addFields(
60  Schema & schema,
61  std::string const & name,
62  std::string const & doc,
63  std::string const & unit,
64  std::vector<T> const & docData
65  );
66 
77  static ArrayKey addFields(
78  Schema & schema,
79  std::string const & name,
80  std::string const & doc,
81  std::string const & unit,
82  int size
83  );
84 
86  ArrayKey() : _begin() {}
87 
89  explicit ArrayKey(std::vector< Key<T> > const & keys);
90 
97  explicit ArrayKey(Key< Array<T> > const & other);
98 
108  ArrayKey(SubSchema const & s);
109 
111  int getSize() const { return _size; }
112 
114  virtual ndarray::Array<T const,1,1> get(BaseRecord const & record) const;
115 
117  virtual void set(BaseRecord & record, ndarray::Array<T const,1,1> const & value) const;
118 
119 #ifndef SWIG
120  virtual ndarray::ArrayRef<T,1,1> getReference(BaseRecord & record) const;
122 
124  virtual ndarray::ArrayRef<T const,1,1> getConstReference(BaseRecord const & record) const;
125 #endif
126 
128  bool operator==(ArrayKey<T> const & other) const {
130  return other._begin == _begin && other._size == _size;
131  }
132  bool operator!=(ArrayKey<T> const & other) const { return !operator==(other); }
134 
136  bool isValid() const { return _begin.isValid(); }
137 
139  Key<T> operator[](int i) const;
140 
142  ArrayKey slice(int begin, int end) const;
143 
144 private:
145 
146  ArrayKey(Key<T> const & begin, int size) : _begin(begin), _size(size) {}
147 
149  int _size;
150 };
151 
152 }}} // namespace lsst::afw::table
153 
154 #endif // !AFW_TABLE_arrays_h_INCLUDED
A proxy class for Array with deep assignment operators.
Definition: ArrayRef.h:46
Defines the fields and offsets for a table.
Definition: Schema.h:46
A FunctorKey used to get or set a ndarray::Array from a sequence of scalar Keys.
Definition: arrays.h:39
A proxy type for name lookups in a Schema.
Definition: Schema.h:330
table::Key< std::string > name
Definition: ApCorrMap.cc:71
ArrayKey slice(int begin, int end) const
Return a FunctorKey corresponding to a range of elements.
ArrayKey(Key< T > const &begin, int size)
Definition: arrays.h:146
bool operator==(ArrayKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition: arrays.h:129
Tag types used to declare specialized field types.
Definition: misc.h:35
static ArrayKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit, std::vector< T > const &docData)
tbl::Schema schema
ArrayKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
Definition: arrays.h:86
A multidimensional strided array.
Definition: Array.h:47
Base class for all records.
Definition: BaseRecord.h:27
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
virtual void set(BaseRecord &record, ndarray::Array< T const, 1, 1 > const &value) const
Set an array in the given record.
bool operator!=(ArrayKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition: arrays.h:132
virtual ndarray::ArrayRef< T const, 1, 1 > getConstReference(BaseRecord const &record) const
Get const reference array from the given record.
int getSize() const
Return the number of elements in the array.
Definition: arrays.h:111
virtual ndarray::ArrayRef< T, 1, 1 > getReference(BaseRecord &record) const
Get non-const reference array from the given record.
bool isValid() const
Return True if the FunctorKey contains valid scalar keys.
Definition: arrays.h:136
Key< T > operator[](int i) const
Return a scalar Key for an element of the array.