-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathTokenTextMap.h
More file actions
82 lines (70 loc) · 2.19 KB
/
Copy pathTokenTextMap.h
File metadata and controls
82 lines (70 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//==============================================================================
//
// TokenTextMap.h
//
// Diplomacy AI Client - Part of the DAIDE project (www.daide.org.uk).
//
// (C) David Norman 2002 david@ellought.demon.co.uk
// (C) Greg Utas 2019-2025 greg@pentennea.com
//
// This software may be reused for non-commercial purposes without charge,
// and without notifying the authors. Use of any part of this software for
// commercial purposes without permission from the authors is prohibited.
//
#ifndef TOKENTEXTMAP_H_INCLUDED
#define TOKENTEXTMAP_H_INCLUDED
#include <map>
#include <string>
#include "DipTypes.h"
namespace Diplomacy
{
class Token;
}
//------------------------------------------------------------------------------
namespace Diplomacy
{
// Provides mappings between raw token values and their text representations.
//
class TokenTextMap
{
public:
// Types for the maps.
//
typedef std::map<Token, std::string> TokenToTextMap;
typedef std::map<std::string, Token> TextToTokenMap;
// Returns the singleton instance of this class.
//
static TokenTextMap* instance();
// Provides read-only access to the token-to-text map.
//
const TokenToTextMap& token_to_text_map()
const { return token_to_text_map_; }
// Provides read-only access to the text-to-token map.
//
const TextToTokenMap& text_to_token_map()
const { return text_to_token_map_; }
// Removes all power and province tokens from the maps.
//
void erase_powers_and_provinces();
// Creates a mapping between TOKEN and TEXT. Returns true on success.
// Returns false and generates a log if TOKEN or TEXT has already been
// inserted.
//
bool insert(const Token& token, const std::string& text);
private:
// Constructor. Calls insert() to create a mapping between every token
// and its text representation.
//
TokenTextMap();
// Removes all tokens in CAT from the maps.
//
void erase(category_t cat);
// The mapping from each token to its text representation.
//
TokenToTextMap token_to_text_map_;
// The mapping from each string to the token it represents.
//
TextToTokenMap text_to_token_map_;
};
}
#endif