-
Notifications
You must be signed in to change notification settings - Fork 1
/
weather-region.hpp
66 lines (50 loc) · 2.1 KB
/
weather-region.hpp
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
#pragma once
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* The original code is copyright (c) 2022, open.mp team and contributors.
*/
// Required for most of open.mp.
#include <sdk.hpp>
// Get pool ID information.
#include <Impl/pool_impl.hpp>
// This is the private implementation of the public interface. We must know the interface.
#include "interface.hpp"
// This entity holds server data, but must use an external service for weather reporting.
#include "api.hpp"
// Import open.mp structures that aren't ABI safe.
using namespace Impl;
// `final` so we don't need virtual destructors. Also because we know it isn't inherited.
class WeatherRegion final
// This class is an implementation of the publicly shared `IWeatherRegion` interface.
: public IWeatherRegion
// This is stored in a pool, so needs a standard pool ID.
, public PoolIDProvider
// Ensure this entity can't be copied without our help.
, public NoCopy
{
private:
// An interface to some immaginary weather lookup system. Web API etc.
SomeExternalAPI api_;
// The last weather loaded from the API, in the API format.
int currentWeather_;
// The name of this small area of localised weather.
String const name_;
// The location of this small area of localised weather.
String const location_;
public:
// Implementations of the various methods from the public API.
StringView getName() const override;
// Get the location. Public APIs use `StringView` because it is ABI stable.
StringView getLocation() const override;
// Convert from the API-specific weather format to the component's global format.
E_WEATHER getWeather() const override;
// Required by anything that is `PoolIDProvider`.
int getID() const override;
// More methods to be used only in this component (internal methods). Implementation details.
WeatherRegion(StringView name, StringView location);
// Only this component should update weather, so don't expose this method.
bool updateWeather();
};