/src/opendnp3/cpp/lib/src/app/DownSampling.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2013-2022 Step Function I/O, LLC |
3 | | * |
4 | | * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O |
5 | | * LLC (https://stepfunc.io) under one or more contributor license agreements. |
6 | | * See the NOTICE file distributed with this work for additional information |
7 | | * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license |
8 | | * this file to you under the Apache License, Version 2.0 (the "License"); you |
9 | | * may not use this file except in compliance with the License. You may obtain |
10 | | * a copy of the License at: |
11 | | * |
12 | | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | | * |
14 | | * Unless required by applicable law or agreed to in writing, software |
15 | | * distributed under the License is distributed on an "AS IS" BASIS, |
16 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | | * See the License for the specific language governing permissions and |
18 | | * limitations under the License. |
19 | | */ |
20 | | #ifndef OPENDNP3_DOWNSAMPLING_H |
21 | | #define OPENDNP3_DOWNSAMPLING_H |
22 | | |
23 | | #include "opendnp3/util/Uncopyable.h" |
24 | | |
25 | | #include <cstdint> |
26 | | #include <limits> |
27 | | |
28 | | namespace opendnp3 |
29 | | { |
30 | | |
31 | | // A safe down sampling class |
32 | | template<class Source, class Target> class DownSampling : private Uncopyable |
33 | | { |
34 | | static const Target TARGET_MAX; |
35 | | static const Target TARGET_MIN; |
36 | | |
37 | | public: |
38 | | static bool Apply(Source src, Target& target) |
39 | 0 | { |
40 | 0 | if (src > TARGET_MAX) |
41 | 0 | { |
42 | 0 | target = TARGET_MAX; |
43 | 0 | return true; |
44 | 0 | } |
45 | 0 | else if (src < TARGET_MIN) |
46 | 0 | { |
47 | 0 | target = TARGET_MIN; |
48 | 0 | return true; |
49 | 0 | } |
50 | 0 | else |
51 | 0 | { |
52 | 0 | target = static_cast<Target>(src); |
53 | 0 | return false; |
54 | 0 | } |
55 | 0 | } Unexecuted instantiation: opendnp3::DownSampling<double, int>::Apply(double, int&) Unexecuted instantiation: opendnp3::DownSampling<double, short>::Apply(double, short&) Unexecuted instantiation: opendnp3::DownSampling<double, float>::Apply(double, float&) |
56 | | }; |
57 | | |
58 | | template<class Source, class Target> |
59 | | const Target DownSampling<Source, Target>::TARGET_MAX(std::numeric_limits<Target>::max()); |
60 | | |
61 | | template<class Source, class Target> |
62 | | const Target DownSampling<Source, Target>::TARGET_MIN(std::numeric_limits<Target>::lowest()); |
63 | | |
64 | | } // namespace opendnp3 |
65 | | |
66 | | #endif |