lsst.astshim  master-gd1207e8857
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
FrameSet.h
1 /*
2  * LSST Data Management System
3  * Copyright 2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #ifndef ASTSHIM_FRAMESET_H
23 #define ASTSHIM_FRAMESET_H
24 
25 #include <memory>
26 #include <sstream>
27 #include <stdexcept>
28 
29 #include "astshim/base.h"
30 #include "astshim/Frame.h"
31 
32 namespace ast {
33 
99 class FrameSet : public Frame {
100 friend class Frame; // so Frame can call the protected raw ptr constructor
101 friend class Object;
102 public:
103  static int constexpr BASE = AST__BASE;
104  static int constexpr CURRENT = AST__CURRENT;
105  static int constexpr NOFRAME = AST__NOFRAME;
106 
116  explicit FrameSet(Frame const & frame, std::string const & options="") :
117  FrameSet(astFrameSet(frame.copy()->getRawPtr(), options.c_str()))
118  {}
119 
130  explicit FrameSet(Frame const & baseFrame, Mapping const & mapping, Frame const & currentFrame,
131  std::string const &options = "")
132  : FrameSet(astFrameSet(baseFrame.copy()->getRawPtr(), options.c_str())) {
133  addFrame(1, mapping, currentFrame);
134  }
135 
136  ~FrameSet() {}
137 
138  FrameSet(FrameSet const &) = delete;
139  FrameSet(FrameSet &&) = default;
140  FrameSet & operator=(FrameSet const &) = delete;
141  FrameSet & operator=(FrameSet &&) = default;
142 
144  std::shared_ptr<FrameSet> copy() const {
145  return std::static_pointer_cast<FrameSet>(_copyPolymorphic());
146  }
147 
160  void addAxes(Frame const & frame) {
161  astAddFrame(getRawPtr(), AST__ALLFRAMES, nullptr, frame.getRawPtr());
162  assertOK();
163  }
164 
208  void addFrame(int iframe, Mapping const & map, Frame const & frame) {
209  if (iframe == AST__ALLFRAMES) {
210  throw std::runtime_error("iframe = AST__ALLFRAMES; call addAxes instead");
211  }
212  // astAddFrame makes deep copies of the map and frame, so no need to do anything extra
213  astAddFrame(getRawPtr(), iframe, map.getRawPtr(), frame.getRawPtr());
214  assertOK();
215  }
216 
237  void addVariant(Mapping const & map, std::string const & name) {
238  astAddVariant(getRawPtr(), map.getRawPtr(), name.c_str());
239  assertOK();
240  }
241 
246  std::string getAllVariants() const { return getC("AllVariants"); }
247 
251  int getBase() const { return getI("Base"); }
252 
256  int getCurrent() const { return getI("Current"); }
257 
266  std::shared_ptr<Frame> getFrame(int iframe) const {
267  auto * rawFrame = reinterpret_cast<AstObject *>(astGetFrame(getRawPtr(), iframe));
268  assertOK(rawFrame);
269  if (!rawFrame) {
270  throw std::runtime_error("getFrame failed (returned a null frame)");
271  }
272  return Object::fromAstObject<Frame>(rawFrame, true);
273  }
274 
300  std::shared_ptr<Mapping> getMapping(int ind1=BASE, int ind2=CURRENT) const {
301  AstObject * rawMap = reinterpret_cast<AstObject *>(astGetMapping(getRawPtr(), ind1, ind2));
302  assertOK(rawMap);
303  if (!rawMap) {
304  throw std::runtime_error("getMapping failed (returned a null mapping)");
305  }
306  return Object::fromAstObject<Mapping>(rawMap, true);
307  }
308 
312  int getNframe() const { return getI("Nframe"); }
313 
319  std::string getVariant() const { return getC("Variant"); }
320 
363  void mirrorVariants(int iframe) {
364  astMirrorVariants(getRawPtr(), iframe);
365  assertOK();
366  }
367 
406  void remapFrame(int iframe, Mapping & map) {
407  astRemapFrame(getRawPtr(), iframe, map.getRawPtr());
408  assertOK();
409  };
410 
438  void removeFrame(int iframe) {
439  astRemoveFrame(getRawPtr(), iframe);
440  assertOK();
441  }
442 
459  void renameVariant(std::string const & name) {
460  astAddVariant(getRawPtr(), nullptr, name.c_str());
461  assertOK();
462  }
463 
467  void setBase(int ind) { setI("Base", ind); }
468 
472  void setCurrent(int ind) { setI("Current", ind); }
473 
474 protected:
475  virtual std::shared_ptr<Object> _copyPolymorphic() const override {
476  return _copyImpl<FrameSet, AstFrameSet>();
477  }
478 
486  explicit FrameSet(AstFrameSet * rawPtr) :
487  Frame(reinterpret_cast<AstFrame *>(rawPtr))
488  {
489  if (!astIsAFrameSet(getRawPtr())) {
490  std::ostringstream os;
491  os << "this is a " << getClass() << ", which is not a FrameSet";
492  throw std::invalid_argument(os.str());
493  }
494  }
495 };
496 
497 } // namespace ast
498 
499 #endif
void addFrame(int iframe, Mapping const &map, Frame const &frame)
Definition: FrameSet.h:208
void remapFrame(int iframe, Mapping &map)
Definition: FrameSet.h:406
void setBase(int ind)
Definition: FrameSet.h:467
FrameSet(AstFrameSet *rawPtr)
Definition: FrameSet.h:486
void setI(std::string const &attrib, int value)
Definition: Object.h:483
Definition: Frame.h:158
int getCurrent() const
Definition: FrameSet.h:256
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:53
std::string getClass() const
Definition: Object.h:117
Definition: FrameSet.h:99
std::string const getC(std::string const &attrib) const
Definition: Object.h:347
Definition: Mapping.h:59
void removeFrame(int iframe)
Definition: FrameSet.h:438
Definition: Object.h:49
void addAxes(Frame const &frame)
Definition: FrameSet.h:160
std::shared_ptr< Mapping > getMapping(int ind1=BASE, int ind2=CURRENT) const
Definition: FrameSet.h:300
static int constexpr BASE
index of base frame
Definition: FrameSet.h:103
void mirrorVariants(int iframe)
Definition: FrameSet.h:363
void setCurrent(int ind)
Definition: FrameSet.h:472
int getNframe() const
Definition: FrameSet.h:312
std::shared_ptr< FrameSet > copy() const
Return a deep copy of this object.
Definition: FrameSet.h:144
int getBase() const
Definition: FrameSet.h:251
std::string getVariant() const
Definition: FrameSet.h:319
std::string getAllVariants() const
Definition: FrameSet.h:246
static int constexpr NOFRAME
an invalid frame index
Definition: FrameSet.h:105
void renameVariant(std::string const &name)
Definition: FrameSet.h:459
virtual std::shared_ptr< Object > _copyPolymorphic() const override
Definition: FrameSet.h:475
FrameSet(Frame const &baseFrame, Mapping const &mapping, Frame const &currentFrame, std::string const &options="")
Definition: FrameSet.h:130
FrameSet(Frame const &frame, std::string const &options="")
Definition: FrameSet.h:116
void addVariant(Mapping const &map, std::string const &name)
Definition: FrameSet.h:237
int getI(std::string const &attrib) const
Definition: Object.h:386
std::shared_ptr< Frame > getFrame(int iframe) const
Definition: FrameSet.h:266
static int constexpr CURRENT
index of current frame
Definition: FrameSet.h:104
AstObject const * getRawPtr() const
Definition: Object.h:260