forked from BoostGSoC19/astronomy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for caching in card ( variant and type sequence ) (Boos…
- Loading branch information
1 parent
8824c60
commit ac8be8f
Showing
2 changed files
with
33 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/*============================================================================= | ||
Copyright 2018 Pranam Lashkari <[email protected]> | ||
Copyright 2020 Gopi Krishna Menon <[email protected]> | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file License.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
|
@@ -14,29 +16,27 @@ file License.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | |
#include <boost/algorithm/string/trim.hpp> | ||
#include <boost/lexical_cast.hpp> | ||
#include <boost/type.hpp> | ||
#include <boost/variant.hpp> | ||
|
||
#include <boost/astronomy/io/default_card_policy.hpp> | ||
#include <boost/astronomy/exception/fits_exception.hpp> | ||
|
||
/** | ||
* @file card.hpp | ||
* @author Pranam Lashkari | ||
* @details Contains the definition for <strong>card</strong> structure | ||
*/ | ||
|
||
|
||
namespace boost { namespace astronomy { namespace io { | ||
|
||
/** | ||
* @brief Represents the concept of <strong>card</strong> associated with the FITS standard. | ||
* @details This structure provides functions for storage, manipulation and access of FITS cards. | ||
* @author Pranam Lashkari | ||
* @author Pranam Lashkari, Gopi Krishna Menon | ||
*/ | ||
template<typename CardPolicy> | ||
struct card: CardPolicy | ||
{ | ||
private: | ||
std::string card_; | ||
typedef typename boost::make_variant_over< typename CardPolicy::supported_types>::type cache; | ||
mutable cache card_cache; | ||
|
||
public: | ||
|
||
|
@@ -146,15 +146,15 @@ struct card: CardPolicy | |
/** | ||
* @brief Returns the value associated with the card | ||
* @tparam ReturnType The type to which the value should be converted and returned | ||
* @pre The ReturnType can be int, long long( If more than 10 digits) ,double,long double,float ,bool,string | ||
* @return The value associated with the card | ||
* @throws boost::bad_lexical_cast If the conversion could not succeed | ||
* @todo Support for complex numbers and date is required | ||
*/ | ||
template <typename ReturnType> | ||
ReturnType value() const | ||
{ | ||
return value_imp(boost::type<ReturnType>()); | ||
if (!value_cached()) { | ||
card_cache =value_imp(boost::type<ReturnType>()); | ||
} | ||
return boost::get<ReturnType>(card_cache); | ||
} | ||
|
||
/** | ||
|
@@ -173,14 +173,14 @@ struct card: CardPolicy | |
template<typename DataType> | ||
void set_value(DataType value) | ||
{ | ||
|
||
std::string serialized_value = this->serialize_to_fits_format(value); | ||
|
||
if (this->is_card_valid(this->keyword(), serialized_value, "")) { | ||
std::string key = this->keyword(true); | ||
this->card_.clear(); | ||
this->card_.append(key); | ||
this->card_.append(serialized_value); | ||
card_cache = value; | ||
} | ||
} | ||
|
||
|
@@ -190,6 +190,11 @@ struct card: CardPolicy | |
const std::string& raw_card() { return card_; } | ||
|
||
private: | ||
/** | ||
* @brief Checks if the value is internally cached | ||
*/ | ||
bool value_cached() const { return card_cache.which() != 0; } | ||
|
||
|
||
/** | ||
* @brief Creates a card from key, value and comment supplied to the method | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters