X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fe2-interface.git;a=blobdiff_plain;f=e2sim%2Fe2apv1sim%2Fsrc%2FASN1%2Fasn%2Fconstraints.hpp;fp=e2sim%2Fe2apv1sim%2Fsrc%2FASN1%2Fasn%2Fconstraints.hpp;h=e8e787d9a00936e0928668ed1ae50527eef21874;hp=0000000000000000000000000000000000000000;hb=0eba05c4ff0c99974d3f3a63b65cbe2adb209e51;hpb=c380e183231711cf9f8bc72d0eb52e532dd07085 diff --git a/e2sim/e2apv1sim/src/ASN1/asn/constraints.hpp b/e2sim/e2apv1sim/src/ASN1/asn/constraints.hpp new file mode 100755 index 0000000..e8e787d --- /dev/null +++ b/e2sim/e2apv1sim/src/ASN1/asn/constraints.hpp @@ -0,0 +1,140 @@ +#pragma once + +/****************************************************************************** +* +* Copyright (c) 2019 AT&T Intellectual Property. +* Copyright (c) 2018-2019 Nokia. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* +******************************************************************************/ + +// Standard Includes: ANSI C/C++, MSA, and Third-Party Libraries +#include +#include +#include +#include + +// Local Includes: Application specific classes, functions, and libraries + +namespace asn { + +using bound_t = int64_t; + +enum class constraint_type : uint8_t +{ + UNCONSTRAINED, + CONSTRAINED, + SEMICONSTRAINED, + CONSTRAINED_EXTENDED, + SEMICONSTRAINED_EXTENDED +}; + +template +struct span +{ + static_assert(UB >= LB, "UPPER >= LOWER"); + static constexpr bound_t lower_bound = LB; + static constexpr bound_t upper_bound = UB; +}; + +template +struct pair +{ + T const lower_bound; + T const upper_bound; +}; + +template +struct one : span {}; + +struct max : one::max()> {}; +struct min : one::min()> {}; + +static constexpr bound_t MAX = std::numeric_limits::max(); +static constexpr bound_t MIN = std::numeric_limits::min(); + +template +struct constraints +{ + static constexpr bool extended = Extended; + static constexpr bound_t lower_bound = std::min({RANGE::lower_bound...}); + static constexpr bound_t upper_bound = std::max({RANGE::upper_bound...}); + + static constexpr constraint_type type = + (Extended && lower_bound > min::lower_bound && upper_bound < max::upper_bound) ? constraint_type::CONSTRAINED_EXTENDED : + (!Extended && lower_bound > min::lower_bound && upper_bound < max::upper_bound) ? constraint_type::CONSTRAINED : + (Extended && lower_bound > min::lower_bound && upper_bound == max::upper_bound) ? constraint_type::SEMICONSTRAINED_EXTENDED : + (!Extended && lower_bound == min::lower_bound && upper_bound < max::upper_bound) ? constraint_type::SEMICONSTRAINED : + (Extended && lower_bound == min::lower_bound && upper_bound < max::upper_bound) ? constraint_type::SEMICONSTRAINED_EXTENDED : + (!Extended && lower_bound > min::lower_bound && upper_bound == max::upper_bound) ? constraint_type::SEMICONSTRAINED : constraint_type::UNCONSTRAINED; + + static constexpr bool is_signed = lower_bound < 0; + + static constexpr bound_t num_spans = static_cast(sizeof...(RANGE)); + static constexpr pair bounds[] = {{RANGE::lower_bound, RANGE::upper_bound}...}; + + using boundary_type = bound_t; + + static constexpr bool is_extended(bound_t val) + { + for (bound_t i = 0; i < num_spans; ++i) + { + auto const& p = bounds[i]; + if (val <= p.upper_bound) + { + if(val < p.lower_bound) + return true; + return false; + } + } + return true; + } +}; + +template +constexpr pair constraints::bounds[]; + +template +struct constraints +{ + static constexpr bool extended = Extended; + static constexpr constraint_type type = constraint_type::UNCONSTRAINED; + static constexpr bound_t lower_bound = std::numeric_limits::min(); + static constexpr bound_t upper_bound = std::numeric_limits::max(); + + static constexpr bool is_extended(bound_t val) {return true;} +}; + +/*************************************************************************************** +* RANGE for sequences +***************************************************************************************/ +template +struct seq_range +{ + static_assert(Extended || TotalNumEntries > 0, "TotalNumEntries must be > 0"); + static_assert(NumExtEntries <= TotalNumEntries, "NumExtEntries must be <= TotalNumEntries"); + + static constexpr constraint_type type = Extended ? constraint_type::CONSTRAINED_EXTENDED : constraint_type::CONSTRAINED; + static constexpr bool extended = Extended; + static constexpr bound_t lower_bound = 0; + static constexpr bound_t upper_bound = TotalNumEntries - NumExtEntries - 1; + static constexpr bound_t default_value = lower_bound; + static constexpr bound_t total_num_entries = TotalNumEntries; + + using boundary_type = bound_t; + using value_type = uint32_t; +}; + +} // namespace asn