define hash struct for scoped enum for header_footer's unordered_map

This commit is contained in:
Thomas Fussell 2016-12-14 11:25:18 +01:00
parent 414fe5da39
commit e250174d1f
3 changed files with 76 additions and 6 deletions

View 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

View File

@ -30,6 +30,7 @@
#include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/formatted_text.hpp>
#include <xlnt/utils/scoped_enum_hash.hpp>
namespace xlnt {
@ -311,12 +312,14 @@ private:
bool different_odd_even_ = false;
bool scale_with_doc_ = false;
std::unordered_map<location, formatted_text> odd_headers_;
std::unordered_map<location, formatted_text> even_headers_;
std::unordered_map<location, formatted_text> first_headers_;
std::unordered_map<location, formatted_text> odd_footers_;
std::unordered_map<location, formatted_text> even_footers_;
std::unordered_map<location, formatted_text> first_footers_;
using container = std::unordered_map<location, formatted_text, scoped_enum_hash<location>>;
container odd_headers_;
container even_headers_;
container first_headers_;
container odd_footers_;
container even_footers_;
container first_footers_;
};
} // namespace xlnt

View File

@ -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
#define EXCEPT_ON_UNHANDLED_SWITCH_CASE