OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
openswmm_api_common.hpp
Go to the documentation of this file.
1
13#ifndef OPENSWMM_API_COMMON_HPP
14#define OPENSWMM_API_COMMON_HPP
15
16#include "SWMMEngine.hpp"
17#include "../../../include/openswmm/engine/openswmm_engine.h"
18
19#include <cstring>
20#include <algorithm>
21
22static inline openswmm::SWMMEngine* to_engine(SWMM_Engine e) noexcept {
23 return static_cast<openswmm::SWMMEngine*>(e);
24}
25
26#define CHECK_HANDLE(e) do { if (!(e)) return SWMM_ERR_BADHANDLE; } while(0)
27#define CHECK_INDEX(cond) do { if (!(cond)) return SWMM_ERR_BADINDEX; } while(0)
28
29// ============================================================================
30// Lifecycle state guards
31// ============================================================================
32
34#define CHECK_GEOMETRY(ctx) \
35 do { \
36 if ((ctx).state != openswmm::EngineState::BUILDING && \
37 (ctx).state != openswmm::EngineState::OPENED) \
38 return SWMM_ERR_LIFECYCLE; \
39 } while(0)
40
46#define CHECK_EDITABLE(ctx) \
47 do { \
48 if ((ctx).state != openswmm::EngineState::BUILDING && \
49 (ctx).state != openswmm::EngineState::OPENED) \
50 return SWMM_ERR_LIFECYCLE; \
51 } while(0)
52
54#define CHECK_INITIAL_COND(ctx) \
55 do { \
56 if ((ctx).state != openswmm::EngineState::BUILDING && \
57 (ctx).state != openswmm::EngineState::OPENED && \
58 (ctx).state != openswmm::EngineState::INITIALIZED) \
59 return SWMM_ERR_LIFECYCLE; \
60 } while(0)
61
63#define CHECK_RUNNING(ctx) \
64 do { \
65 if ((ctx).state != openswmm::EngineState::RUNNING) \
66 return SWMM_ERR_LIFECYCLE; \
67 } while(0)
68
70#define CHECK_READABLE(ctx) \
71 do { \
72 if ((ctx).state == openswmm::EngineState::CREATED || \
73 (ctx).state == openswmm::EngineState::CLOSED || \
74 (ctx).state == openswmm::EngineState::ERROR_STATE) \
75 return SWMM_ERR_LIFECYCLE; \
76 } while(0)
77
78#endif /* OPENSWMM_API_COMMON_HPP */
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:35