mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 14:49:19 +02:00
stl-based names class replacement, re-enabled cab camera shake, enhanced parser comment support, minor bug fixes.
This commit is contained in:
61
Names.h
61
Names.h
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
@@ -7,8 +8,64 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#ifndef NamesH
|
||||
#define NamesH
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
template <typename _Pointer>
|
||||
class TNames {
|
||||
|
||||
public:
|
||||
// types:
|
||||
|
||||
// constructors:
|
||||
TNames() = default;
|
||||
|
||||
// destructor:
|
||||
|
||||
// methods:
|
||||
// dodanie obiektu z wskaźnikiem. updates data field if the object already exists. returns true for insertion, false for update
|
||||
bool
|
||||
Add( int const Type, std::string const &Name, _Pointer Data ) {
|
||||
|
||||
auto lookup = find_map( Type ).emplace( Name, Data );
|
||||
if( lookup.second == false ) {
|
||||
// record already exists, update it
|
||||
lookup.first->second = Data;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// new record inserted, bail out
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// returns pointer associated with provided label, or nullptr if there's no match
|
||||
_Pointer
|
||||
Find( int const Type, std::string const &Name ) {
|
||||
|
||||
auto const &map = find_map( Type );
|
||||
auto const lookup = map.find( Name );
|
||||
if( lookup != map.end() ) { return lookup->second; }
|
||||
else { return nullptr; }
|
||||
}
|
||||
|
||||
private:
|
||||
// types:
|
||||
typedef std::unordered_map<std::string, _Pointer> pointer_map;
|
||||
typedef std::unordered_map<int, pointer_map> pointermap_map;
|
||||
|
||||
// methods:
|
||||
// returns database stored with specified type key; creates new database if needed.
|
||||
pointer_map &
|
||||
find_map( int const Type ) {
|
||||
|
||||
return m_maps.emplace( Type, pointer_map() ).first->second;
|
||||
}
|
||||
|
||||
// members:
|
||||
pointermap_map m_maps; // list of pointer maps of types specified so far
|
||||
};
|
||||
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
//---------------------------------------------------------------------------
|
||||
class ItemRecord
|
||||
{ // rekord opisujący obiekt; raz utworzony nie przemieszcza się
|
||||
|
||||
Reference in New Issue
Block a user