-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
062aafd
commit 0b73c32
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
tesseract_common/include/tesseract_common/atomic_serialization.h
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @file atomic_serialization.h | ||
* @brief Additional Boost serialization wrappers | ||
* @details Support for atomic serialization | ||
* | ||
* @author Levi Armstrong | ||
* @date March 24, 2022 | ||
* @version TODO | ||
* @bug No known bugs | ||
* | ||
* @copyright Copyright (c) 2022, Levi Armstrong | ||
* | ||
* @par License | ||
* Software License Agreement (Apache License) | ||
* @par | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* @par | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef TESSERACT_COMMON_ATOMIC_SERIALIZATION_H | ||
#define TESSERACT_COMMON_ATOMIC_SERIALIZATION_H | ||
|
||
#include <tesseract_common/macros.h> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH | ||
#include <boost/serialization/serialization.hpp> | ||
#include <boost/serialization/split_free.hpp> | ||
#include <atomic> | ||
TESSERACT_COMMON_IGNORE_WARNINGS_POP | ||
|
||
/** @note When using this header only include it in the cpp never in the header */ | ||
namespace boost::serialization | ||
{ | ||
template <class Archive, class T> | ||
inline void save(Archive& ar, const std::atomic<T>& t, const unsigned int) | ||
{ | ||
const T value = t.load(); | ||
ar << value; | ||
} | ||
|
||
template <class Archive, class T> | ||
inline void load(Archive& ar, std::atomic<T>& t, const unsigned int) | ||
{ | ||
T value; | ||
ar >> value; | ||
t = value; | ||
} | ||
|
||
template <class Archive, class T> | ||
inline void serialize(Archive& ar, std::atomic<T>& t, const unsigned int file_version) | ||
{ | ||
boost::serialization::split_free(ar, t, file_version); | ||
} | ||
} // namespace boost::serialization | ||
#endif // TESSERACT_COMMON_ATOMIC_SERIALIZATION_H |