Skip to content

Commit

Permalink
format C++ code with clang format (#465)
Browse files Browse the repository at this point in the history
* style: run clang format

* fix documentation

---------

Co-authored-by: ChristineStawitz-NOAA <ChristineStawitz-NOAA@users.noreply.github.com>
Co-authored-by: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 29, 2023
1 parent 6f206a9 commit 1995781
Show file tree
Hide file tree
Showing 10 changed files with 1,041 additions and 1,121 deletions.
6 changes: 3 additions & 3 deletions inst/include/interface/rcpp/rcpp_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ void clear_internal() {
void clear() {
// rcpp_interface_base.hpp
FIMSRcppInterfaceBase::fims_interface_objects.clear();

// rcpp_data.hpp
DataInterfaceBase::id_g = 1;
DataInterfaceBase::live_objects.clear();

AgeCompDataInterface::id_g = 1;
AgeCompDataInterface::live_objects.clear();

Expand All @@ -108,7 +108,7 @@ void clear() {

// rcpp_fleets.hpp
FleetInterfaceBase::id_g = 1;
FleetInterfaceBase::live_objects.clear();
FleetInterfaceBase::live_objects.clear();

FleetInterface::id_g = 1;
FleetInterface::live_objects.clear();
Expand Down
248 changes: 116 additions & 132 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,37 @@
*
*/
class DataInterfaceBase : public FIMSRcppInterfaceBase {
public:
Rcpp::NumericVector observed_data; /*!< The data */
static uint32_t id_g; /**< static id of the DataInterfaceBase object */
uint32_t id; /**< local id of the DataInterfaceBase object */
//live objects in C++ are objects that have been created and live in memory
static std::map<uint32_t, DataInterfaceBase*>
live_objects; /**< map associating the ids of DataInterfaceBase to
the objects */

/** @brief constructor
*/
DataInterfaceBase() {
this->id = DataInterfaceBase::id_g++;
//Create instance of map: key is id and value is pointer to DataInterfaceBase
DataInterfaceBase::live_objects[this->id] = this;
FIMSRcppInterfaceBase::fims_interface_objects.push_back(this);
}

/** @brief destructor
*/
virtual ~DataInterfaceBase() {
}

/** @brief get the ID of the interface base object
**/
virtual uint32_t get_id() {
return this->id;
}

/**@brief add_to_fims_tmb dummy method
*
*/
virtual bool add_to_fims_tmb() {
return true;
};
public:
Rcpp::NumericVector observed_data; /*!< The data */
static uint32_t id_g; /**< static id of the DataInterfaceBase object */
uint32_t id; /**< local id of the DataInterfaceBase object */
// live objects in C++ are objects that have been created and live in memory
static std::map<uint32_t, DataInterfaceBase*>
live_objects; /**< map associating the ids of DataInterfaceBase to
the objects */

/** @brief constructor
*/
DataInterfaceBase() {
this->id = DataInterfaceBase::id_g++;
/* Create instance of map: key is id and value is pointer to
DataInterfaceBase */
DataInterfaceBase::live_objects[this->id] = this;
FIMSRcppInterfaceBase::fims_interface_objects.push_back(this);
}

/** @brief destructor
*/
virtual ~DataInterfaceBase() {}

/** @brief get the ID of the interface base object
**/
virtual uint32_t get_id() { return this->id; }

/**@brief add_to_fims_tmb dummy method
*
*/
virtual bool add_to_fims_tmb() { return true; };
};
uint32_t DataInterfaceBase::id_g = 1;
std::map<uint32_t, DataInterfaceBase*> DataInterfaceBase::live_objects;
Expand All @@ -63,67 +59,62 @@ std::map<uint32_t, DataInterfaceBase*> DataInterfaceBase::live_objects;
* acomp <- new(fims$AgeComp)
*/
class AgeCompDataInterface : public DataInterfaceBase {
public:
int amax; /*!< first dimension of the data */
int ymax; /*!< second dimension of the data */
Rcpp::NumericVector age_comp_data; /*!<the age composition data*/

/**
* @brief constructor
*/
AgeCompDataInterface(int ymax = 0, int amax = 0) : DataInterfaceBase() {
this->amax = amax;
this->ymax = ymax;
}
public:
int amax; /*!< first dimension of the data */
int ymax; /*!< second dimension of the data */
Rcpp::NumericVector age_comp_data; /*!<the age composition data*/

/**
* @brief constructor
*/
AgeCompDataInterface(int ymax = 0, int amax = 0) : DataInterfaceBase() {
this->amax = amax;
this->ymax = ymax;
}

/**
* @brief destructor
*/
virtual ~AgeCompDataInterface() {}

/** @brief get the ID of the interface base object
**/
virtual uint32_t get_id() { return this->id; }

/**
* @brief destructor
*/
virtual ~AgeCompDataInterface() {
}
#ifdef TMB_MODEL

/** @brief get the ID of the interface base object
**/
virtual uint32_t get_id() {
return this->id;
template <typename Type>
bool add_to_fims_tmb_internal() {
std::shared_ptr<fims::DataObject<Type>> age_comp_data =
std::make_shared<fims::DataObject<Type>>(this->ymax, this->amax);

age_comp_data->id = this->id;
for (int y = 0; y < ymax; y++) {
for (int a = 0; a < amax; a++) {
int index_ya = y * amax + a;
age_comp_data->at(y, a) = this->age_comp_data[index_ya];
}
}

std::shared_ptr<fims::Information<Type>> info =
fims::Information<Type>::GetInstance();

#ifdef TMB_MODEL
info->data_objects[this->id] = age_comp_data;

template<typename Type>
bool add_to_fims_tmb_internal() {
std::shared_ptr<fims::DataObject < Type>> age_comp_data =
std::make_shared<fims::DataObject < Type >> (this->ymax,
this->amax);

age_comp_data->id = this->id;
for (int y = 0; y < ymax; y++) {
for (int a = 0; a < amax; a++) {
int index_ya = y * amax + a;
age_comp_data->at(y, a) = this->age_comp_data[index_ya];
}
}

std::shared_ptr<fims::Information < Type>> info =
fims::Information<Type>::GetInstance();

info->data_objects[this->id] = age_comp_data;

return true;
}
return true;
}

/**
* @brief adds parameters to the model
*/
virtual bool add_to_fims_tmb() {
this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
this->add_to_fims_tmb_internal<TMB_FIMS_FIRST_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_SECOND_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_THIRD_ORDER>();
/**
* @brief adds parameters to the model
*/
virtual bool add_to_fims_tmb() {
this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
this->add_to_fims_tmb_internal<TMB_FIMS_FIRST_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_SECOND_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_THIRD_ORDER>();

return true;
}
return true;
}

#endif
};
Expand All @@ -134,62 +125,55 @@ class AgeCompDataInterface : public DataInterfaceBase {
* fleet <- new(fims$Index)
*/
class IndexDataInterface : public DataInterfaceBase {
public:
int ymax; /*!< second dimension of the data */
Rcpp::NumericVector index_data; /*!<the age composition data*/

/**
* @brief constructor
*/
IndexDataInterface(int ymax = 0) : DataInterfaceBase() {
this->ymax = ymax;
}
public:
int ymax; /*!< second dimension of the data */
Rcpp::NumericVector index_data; /*!<the age composition data*/

/**
* @brief destructor
*/
virtual ~IndexDataInterface() {
}
/**
* @brief constructor
*/
IndexDataInterface(int ymax = 0) : DataInterfaceBase() { this->ymax = ymax; }

/** @brief get the ID of the interface base object
**/
virtual uint32_t get_id() {
return this->id;
}
/**
* @brief destructor
*/
virtual ~IndexDataInterface() {}

/** @brief get the ID of the interface base object
**/
virtual uint32_t get_id() { return this->id; }

#ifdef TMB_MODEL

template<typename T>
bool add_to_fims_tmb_internal() {
std::shared_ptr<fims::DataObject < T>> data =
std::make_shared<fims::DataObject < T >> (this->ymax);
template <typename T>
bool add_to_fims_tmb_internal() {
std::shared_ptr<fims::DataObject<T>> data =
std::make_shared<fims::DataObject<T>>(this->ymax);

data->id = this->id;
data->id = this->id;

for (int y = 0; y < ymax; y++) {
data->at(y) = this->index_data[y];
}

std::shared_ptr<fims::Information < T>> info =
fims::Information<T>::GetInstance();

info->data_objects[this->id] = data;
return true;
for (int y = 0; y < ymax; y++) {
data->at(y) = this->index_data[y];
}

/**
*@brief function to add to TMB
*/
virtual bool add_to_fims_tmb() {
std::shared_ptr<fims::Information<T>> info =
fims::Information<T>::GetInstance();

this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
this->add_to_fims_tmb_internal<TMB_FIMS_FIRST_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_SECOND_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_THIRD_ORDER>();
info->data_objects[this->id] = data;
return true;
}

return true;
}
/**
*@brief function to add to TMB
*/
virtual bool add_to_fims_tmb() {
this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
this->add_to_fims_tmb_internal<TMB_FIMS_FIRST_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_SECOND_ORDER>();
this->add_to_fims_tmb_internal<TMB_FIMS_THIRD_ORDER>();

return true;
}

#endif
};
Expand Down
Loading

0 comments on commit 1995781

Please sign in to comment.