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
Simple.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 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_Simple_h_INCLUDED
24 #define AFW_TABLE_Simple_h_INCLUDED
25 
29 #include "lsst/afw/table/Catalog.h"
33 
34 namespace lsst { namespace afw { namespace table {
35 
36 class SimpleRecord;
37 class SimpleTable;
38 
46 class SimpleRecord : public BaseRecord {
47 public:
48 
49  typedef SimpleTable Table;
53 
55  return boost::static_pointer_cast<SimpleTable const>(BaseRecord::getTable());
56  }
57 
59  RecordId getId() const;
61  void setId(RecordId id);
62 
63  IcrsCoord getCoord() const;
64  void setCoord(IcrsCoord const & coord);
65  void setCoord(Coord const & coord);
66 
67  Angle getRa() const;
68  void setRa(Angle ra);
69 
70  Angle getDec() const;
71  void setDec(Angle dec);
73 
74 protected:
75 
77 
78 };
79 
85 class SimpleTable : public BaseTable {
86 public:
87 
92 
103  static PTR(SimpleTable) make(Schema const & schema, PTR(IdFactory) const & idFactory);
104 
112  static PTR(SimpleTable) make(Schema const & schema) { return make(schema, IdFactory::makeSimple()); }
113 
123  r.disconnectAliases();
124  return r;
125  }
126 
133  static bool checkSchema(Schema const & other) {
134  return other.contains(getMinimalSchema().schema);
135  }
136 
139 
142 
145 
147 
152  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
157 
159  PTR(SimpleTable) clone() const { return boost::static_pointer_cast<SimpleTable>(_clone()); }
160 
162  PTR(SimpleRecord) makeRecord() { return boost::static_pointer_cast<SimpleRecord>(_makeRecord()); }
163 
166  return boost::static_pointer_cast<SimpleRecord>(BaseTable::copyRecord(other));
167  }
168 
170  PTR(SimpleRecord) copyRecord(BaseRecord const & other, SchemaMapper const & mapper) {
171  return boost::static_pointer_cast<SimpleRecord>(BaseTable::copyRecord(other, mapper));
172  }
173 
174 protected:
175 
176  SimpleTable(Schema const & schema, PTR(IdFactory) const & idFactory);
177 
178  SimpleTable(SimpleTable const & other);
179 
180 private:
181 
182  // Struct that holds the minimal schema and the special keys we've added to it.
183  struct MinimalSchema {
187 
188  MinimalSchema();
189  };
190 
191  // Return the singleton minimal schema.
192  static MinimalSchema & getMinimalSchema();
193 
194  friend class io::FitsWriter;
195 
196  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
197  virtual PTR(io::FitsWriter) makeFitsWriter(fits::Fits * fitsfile, int flags) const;
198 
199  PTR(IdFactory) _idFactory; // generates IDs for new records
200 };
201 
202 #ifndef SWIG
203 
204 inline RecordId SimpleRecord::getId() const { return get(SimpleTable::getIdKey()); }
205 inline void SimpleRecord::setId(RecordId id) { set(SimpleTable::getIdKey(), id); }
206 
208 inline void SimpleRecord::setCoord(IcrsCoord const & coord) { set(SimpleTable::getCoordKey(), coord); }
209 inline void SimpleRecord::setCoord(Coord const & coord) { SimpleTable::getCoordKey().set(*this, coord); }
210 
211 inline Angle SimpleRecord::getRa() const { return get(SimpleTable::getCoordKey().getRa()); }
212 inline void SimpleRecord::setRa(Angle ra) { set(SimpleTable::getCoordKey().getRa(), ra); }
213 
214 inline Angle SimpleRecord::getDec() const { return get(SimpleTable::getCoordKey().getDec()); }
215 inline void SimpleRecord::setDec(Angle dec) { set(SimpleTable::getCoordKey().getDec(), dec); }
216 
217 #endif // !SWIG
218 
219 }}} // namespace lsst::afw::table
220 
221 #endif // !AFW_TABLE_Simple_h_INCLUDED
boost::shared_ptr< IdFactory > _idFactory
Definition: Simple.h:199
Defines the fields and offsets for a table.
Definition: Schema.h:46
void setId(RecordId id)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:205
SortedCatalogT< Record const > ConstCatalog
Definition: Simple.h:91
Key< geom::Angle > getRa() const
Return a constituent Key.
Definition: aggregates.h:170
Writer object for FITS binary tables.
Definition: FitsWriter.h:22
virtual void set(BaseRecord &record, coord::IcrsCoord const &value) const
Set an IcrsCoord in the given record.
#define PTR(...)
Definition: base.h:41
SortedCatalogT< SimpleRecord > Catalog
Definition: Simple.h:51
boost::shared_ptr< SimpleTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Simple.h:159
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
Definition: Simple.h:121
static CoordKey getCoordKey()
Key for the celestial coordinates.
Definition: Simple.h:155
static boost::shared_ptr< SimpleTable > make(Schema const &schema)
Construct a new table.
Definition: Simple.h:112
boost::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:51
#define CONST_PTR(...)
Definition: base.h:47
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:50
boost::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:138
static boost::shared_ptr< SimpleTable > make(Schema const &schema, boost::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
RecordId getId() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:204
virtual boost::shared_ptr< BaseTable > _clone() const =0
Clone implementation with noncovariant return types.
static boost::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
static MinimalSchema & getMinimalSchema()
SimpleRecord(boost::shared_ptr< SimpleTable > const &table)
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid SimpleTable schema.
Definition: Simple.h:133
virtual boost::shared_ptr< BaseRecord > _makeRecord()=0
Default-construct an associated record (protected implementation).
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
SortedCatalogT< Record > Catalog
Definition: Simple.h:90
IcrsCoord getCoord() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:207
Table class that must contain a unique ID field and a celestial coordinate field. ...
Definition: Simple.h:85
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
void setIdFactory(boost::shared_ptr< IdFactory > f)
Switch to a new IdFactory – object that generates IDs for the table (may be null).
Definition: Simple.h:144
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:55
SimpleRecord Record
Definition: Simple.h:88
virtual boost::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
boost::shared_ptr< SimpleRecord > makeRecord()
Default-construct an associated record.
Definition: Simple.h:162
static Key< RecordId > getIdKey()
Key for the unique ID.
Definition: Simple.h:153
tbl::Schema schema
A polymorphic functor base class for generating record IDs for a table.
Definition: IdFactory.h:19
boost::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:89
void setCoord(IcrsCoord const &coord)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:208
Base class for all records.
Definition: BaseRecord.h:27
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:171
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
Angle getDec() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:214
SimpleTable(Schema const &schema, boost::shared_ptr< IdFactory > const &idFactory)
void setDec(Angle dec)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:215
boost::shared_ptr< SimpleRecord > copyRecord(BaseRecord const &other)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: Simple.h:165
Record class that must contain a unique ID field and a celestial coordinate field.
Definition: Simple.h:46
boost::shared_ptr< SimpleTable const > getTable() const
Definition: Simple.h:54
SortedCatalogT< SimpleRecord const > ConstCatalog
Definition: Simple.h:52
boost::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:21
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:157
void setRa(Angle ra)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:212
Base class for all tables.
Definition: BaseTable.h:44
Angle getRa() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:211
A FunctorKey used to get or set celestial coordiantes from a pair of Angle keys.
Definition: aggregates.h:119