mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
define hash struct for scoped enum for header_footer's unordered_map
This commit is contained in:
parent
414fe5da39
commit
e250174d1f
44
include/xlnt/utils/scoped_enum_hash.hpp
Normal file
44
include/xlnt/utils/scoped_enum_hash.hpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
// Copyright (c) 2016 Thomas Fussell
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE
|
||||||
|
//
|
||||||
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||||
|
// @author: see AUTHORS file
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <utility> // for std::hash
|
||||||
|
|
||||||
|
namespace xlnt {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows a scoped enum (aka "enum class") to be used as a key
|
||||||
|
/// in a std::unordered_map.
|
||||||
|
/// </summary>
|
||||||
|
template<typename Enum>
|
||||||
|
struct scoped_enum_hash
|
||||||
|
{
|
||||||
|
std::size_t operator()(Enum e) const
|
||||||
|
{
|
||||||
|
static std::hash<std::size_t> hasher;
|
||||||
|
return hasher(static_cast<std::size_t>(e));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace xlnt
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include <xlnt/xlnt_config.hpp>
|
#include <xlnt/xlnt_config.hpp>
|
||||||
#include <xlnt/cell/formatted_text.hpp>
|
#include <xlnt/cell/formatted_text.hpp>
|
||||||
|
#include <xlnt/utils/scoped_enum_hash.hpp>
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
|
|
||||||
|
@ -311,12 +312,14 @@ private:
|
||||||
bool different_odd_even_ = false;
|
bool different_odd_even_ = false;
|
||||||
bool scale_with_doc_ = false;
|
bool scale_with_doc_ = false;
|
||||||
|
|
||||||
std::unordered_map<location, formatted_text> odd_headers_;
|
using container = std::unordered_map<location, formatted_text, scoped_enum_hash<location>>;
|
||||||
std::unordered_map<location, formatted_text> even_headers_;
|
|
||||||
std::unordered_map<location, formatted_text> first_headers_;
|
container odd_headers_;
|
||||||
std::unordered_map<location, formatted_text> odd_footers_;
|
container even_headers_;
|
||||||
std::unordered_map<location, formatted_text> even_footers_;
|
container first_headers_;
|
||||||
std::unordered_map<location, formatted_text> first_footers_;
|
container odd_footers_;
|
||||||
|
container even_footers_;
|
||||||
|
container first_footers_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
// Copyright (c) 2016 Thomas Fussell
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE
|
||||||
|
//
|
||||||
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||||
|
// @author: see AUTHORS file
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define EXCEPT_ON_UNHANDLED_SWITCH_CASE
|
#define EXCEPT_ON_UNHANDLED_SWITCH_CASE
|
||||||
|
|
Loading…
Reference in New Issue
Block a user