Skip to content
Snippets Groups Projects
Commit c8e63d69 authored by Maik Nijhuis's avatar Maik Nijhuis
Browse files

Remove MutablePtr and Station::Set* members

parent 0b2c4894
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: GPL-3.0-or-later
install(
FILES constants.h
casautils.h
mathutils.h
mutable_ptr.h
types.h
fftresampler.h
install(FILES constants.h casautils.h mathutils.h types.h fftresampler.h
sphericalharmonics.h
DESTINATION "include/${CMAKE_PROJECT_NAME}/common")
// mutableptr.h: Representation of an LBA antenna field.
//
// Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef EVERYBEAM_MUTABLEPTR_H
#define EVERYBEAM_MUTABLEPTR_H
#include <memory>
namespace everybeam {
namespace common {
/*!
* \brief MutablePtr is a mutable smart pointer derived from std::shared_ptr.
*
* Its purpose is to have a pointer that
* 1. can by copied/passed by value,
* 2. the original can be modified after it has been copied
* 3. the copies will dereference to the new value
*
* This behaviour is different from a `reset` of a std::shared_ptr
* There the copies will keep pointing to the original object
*
* The inner pointer is a shared_ptr which manages the object it points to
*
* Usage:
*
* \code
* #include<iostream>
* #include "mutable_ptr.h"
*
* class Msg {
* public:
* Msg(const std::string &t) : text(t) {}
* std::string text;
* };
*
* typedef MutablePtr<Msg> MsgMutPtr;
*
* int main()
* {
* auto m1 = std::make_shared<Msg>("hoi");
* auto m2 = std::make_shared<Msg>("hallo");
*
* MsgPtr mut_ptr(m1);
* auto mut_ptr_copy = mut_ptr;
*
* mut_ptr.set(m2);
*
* std::cout << mut_ptr->text << std::endl;
* std::cout << mut_ptr_copy->text << std::endl;
*
* // Output:
* // Greetings from object number two
* // Greetings from object number two
*
* \endcode
*/
template <typename T>
class MutablePtr : public std::shared_ptr<std::shared_ptr<T>> {
public:
MutablePtr(std::shared_ptr<T> ptr)
: std::shared_ptr<std::shared_ptr<T>>(new std::shared_ptr<T>(ptr)) {}
T& operator*() const { return **(this->get()); }
std::shared_ptr<T> operator->() const { return *(this->get()); }
void set(std::shared_ptr<T> ptr) { *(this->get()) = ptr; }
explicit operator bool() const noexcept { return **this; }
};
} // namespace common
} // namespace everybeam
#endif
......@@ -11,16 +11,10 @@
#include <aocommon/matrix2x2.h>
#include "common/mutable_ptr.h"
#include "common/types.h"
namespace everybeam {
namespace common {
template <typename T>
class MutablePtr;
}
struct Options;
enum class ElementResponseModel {
......@@ -60,9 +54,6 @@ class ElementResponse : public std::enable_shared_from_this<ElementResponse> {
public:
virtual ~ElementResponse() {}
typedef common::MutablePtr<ElementResponse>
Ptr; //!< Pointer to ElementResponse object
virtual ElementResponseModel GetModel() const = 0;
/**
......
......@@ -24,14 +24,6 @@ Station::Station(const std::string& name, const vector3r_t& position,
ncp_pol0_.reset(new coords::ITRFDirection(ncppol0));
}
void Station::SetResponseModel(const ElementResponseModel model) {
element_response_.set(ElementResponse::GetInstance(model, name_, options_));
}
void Station::SetResponse(std::shared_ptr<ElementResponse> element_response) {
element_response_.set(element_response);
}
const std::string& Station::GetName() const { return name_; }
const vector3r_t& Station::GetPosition() const { return position_; }
......
......@@ -35,8 +35,6 @@ class Station {
Station(const std::string& name, const vector3r_t& position,
const Options& options = Options());
void SetResponse(std::shared_ptr<ElementResponse> element_response);
//! Return the name of the station.
const std::string& GetName() const;
......@@ -262,7 +260,7 @@ class Station {
//! Returns a pointer to the ElementResponse class
std::shared_ptr<const ElementResponse> GetElementResponse() const {
return *element_response_.get();
return element_response_;
}
/**
......@@ -310,8 +308,6 @@ class Station {
std::shared_ptr<Antenna> GetAntenna() const { return antenna_; }
private:
void SetResponseModel(const ElementResponseModel model);
vector3r_t NCP(real_t time) const;
vector3r_t NCPPol0(real_t time) const;
......@@ -319,7 +315,7 @@ class Station {
vector3r_t position_;
Options options_;
vector3r_t phase_reference_;
ElementResponse::Ptr element_response_;
std::shared_ptr<const ElementResponse> element_response_;
// element_ either refers to antenna_ or an Element inside antenna_.
// Besides Station, no one has (shared) ownership of antenna_.
std::shared_ptr<Element> element_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment