Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
wildcard.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file ored/utilities/wildcard.hpp
20 \brief utilities for wildcard handling
21 \ingroup utilities
22*/
23
24#pragma once
25
26#include <boost/optional.hpp>
27#include <ql/shared_ptr.hpp>
28
29#include <regex>
30#include <set>
31#include <string>
32
33namespace ore {
34namespace data {
35
36class Wildcard {
37public:
38 /*! all characters in s keep their original meaning except * which is a placeholder for zero or
39 more characters not equal to newline */
40 explicit Wildcard(const std::string& pattern, const bool usePrefixes = true, const bool aggressivePrefixes = false);
41
42 bool hasWildcard() const;
43 std::size_t wildcardPos() const; // string::npos if hasWildcard() == false
44 bool isPrefix() const;
45
46 bool matches(const std::string& s) const;
47
48 const std::string& pattern() const;
49 const std::string& regex() const;
50 const std::string& prefix() const;
51
52private:
53 std::string pattern_;
56
57 bool hasWildCard_ = false;
58 std::size_t wildCardPos_;
59 boost::optional<std::string> regexString_;
60 boost::optional<std::string> prefixString_;
61 mutable QuantLib::ext::shared_ptr<std::regex> regex_;
62};
63
64//! checks if at most one element in C has a wild card and returns it in this case
65template <class C> boost::optional<Wildcard> getUniqueWildcard(const C& c) {
66 for (auto const& a : c) {
67 Wildcard w(a);
68 if (w.hasWildcard()) {
69 QL_REQUIRE(c.size() == 1, "If wild cards are used, only one entry should exist.");
70 return w;
71 }
72 }
73 return boost::none;
74}
75
76// The quoteNames set can have a mix of exact RIC names and regex strings to match multiple RICs. This function splits
77// them into two separate sets.
78void partitionQuotes(const std::set<std::string>& quoteNames, std::set<std::string>& names,
79 std::set<std::string>& regexes);
80
81// As above, but the split is into names, regexes and prefixes
82void partitionQuotes(const std::set<std::string>& quoteNames, std::set<std::string>& names,
83 std::set<std::string>& regexes, std::set<std::string>& prefixes,
84 const bool aggressivePrefixes = false);
85
86} // namespace data
87} // namespace ore
bool isPrefix() const
Definition: wildcard.cpp:66
bool hasWildcard() const
Definition: wildcard.cpp:62
boost::optional< std::string > prefixString_
Definition: wildcard.hpp:60
const std::string & pattern() const
Definition: wildcard.cpp:80
bool matches(const std::string &s) const
Definition: wildcard.cpp:68
std::size_t wildcardPos() const
Definition: wildcard.cpp:64
boost::optional< std::string > regexString_
Definition: wildcard.hpp:59
std::size_t wildCardPos_
Definition: wildcard.hpp:58
QuantLib::ext::shared_ptr< std::regex > regex_
Definition: wildcard.hpp:61
const std::string & prefix() const
Definition: wildcard.cpp:89
std::string pattern_
Definition: wildcard.hpp:53
const std::string & regex() const
Definition: wildcard.cpp:82
@ data
Definition: log.hpp:77
void partitionQuotes(const set< string > &quoteNames, set< string > &names, set< string > &regexes)
Definition: wildcard.cpp:96
boost::optional< Wildcard > getUniqueWildcard(const C &c)
checks if at most one element in C has a wild card and returns it in this case
Definition: wildcard.hpp:65
Serializable Credit Default Swap.
Definition: namespaces.docs:23