OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
RdiiInterface.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
47
48#ifndef OPENSWMM_RDII_INTERFACE_HPP
49#define OPENSWMM_RDII_INTERFACE_HPP
50
51#include <cstdio>
52#include <string>
53#include <vector>
54
55namespace openswmm {
56
58
59namespace rdii_iface {
60
61static const char RDII_FILE_STAMP[] = "SWMM5-RDII";
62
70public:
74
84 int openForRead(SimulationContext& ctx, const std::string& path);
85
94 int openForWrite(const std::string& path, int rdii_step, const std::vector<int>& node_idx);
95
105 void applyFlows(SimulationContext& ctx, double current_date);
106
115 void saveFlows(double current_date, const std::vector<double>& node_flows);
116
120 void close();
121
124 bool isOpen() const { return fp_ != nullptr; }
127 bool isWriting() const { return writing_; }
131 int step() const { return rdii_step_; }
132
133private:
134 std::FILE* fp_ = nullptr;
135 bool writing_ = false;
136 bool binary_ = true;
137
138 int rdii_step_ = 0;
139 int flow_units_ = 0;
140 std::vector<int> node_idx_;
141 std::vector<float> flows_;
142 double start_date_ = 0.0;
143 double end_date_ = 0.0;
144 bool have_record_ = false;
145
152 int readBinaryHeader(SimulationContext& ctx);
160 int readTextHeader(SimulationContext& ctx);
168 bool readNextRecord();
169};
170
171} // namespace rdii_iface
172} // namespace openswmm
173
174#endif // OPENSWMM_RDII_INTERFACE_HPP
RDII interface file manager (USE = read/override, SAVE = export).
Definition RdiiInterface.hpp:69
bool isWriting() const
Read the current mode flag without checking stream/error state.
Definition RdiiInterface.hpp:127
int openForRead(SimulationContext &ctx, const std::string &path)
Replace the owned stream with a binary or text RDII input and prime a record.
Definition RdiiInterface.cpp:55
bool isOpen() const
Test stream ownership without checking EOF or error state.
Definition RdiiInterface.hpp:124
~RdiiInterfaceFile()
Close the owned stream, ignoring flush/close failure. Caller first ends active access; does not publi...
Definition RdiiInterface.hpp:73
void applyFlows(SimulationContext &ctx, double current_date)
Add the bracketing record's RDII flow into the context node accumulators.
Definition RdiiInterface.cpp:243
int openForWrite(const std::string &path, int rdii_step, const std::vector< int > &node_idx)
Close prior IO, truncate a binary RDII destination and write its header.
Definition RdiiInterface.cpp:274
int step() const
Read the last stored record-validity duration.
Definition RdiiInterface.hpp:131
void close()
Close owned IO and clear writing/have-record flags. Ignores fclose status; retains step,...
Definition RdiiInterface.cpp:320
void saveFlows(double current_date, const std::vector< double > &node_flows)
Append a native double date and float cfs values for selected node indices.
Definition RdiiInterface.cpp:304
Definition RdiiInterface.cpp:44
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390