Cambridge SMT System
addresshandler.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
21 #ifndef ADDRESSHANDLER_HPP
22 #define ADDRESSHANDLER_HPP
23 
24 namespace ucam {
25 namespace util {
32 template<typename T = uint>
34  private:
36  std::string address_;
38  std::string wildcard_;
39 
40  public:
41 
48  PatternAddress ( const std::string& address,
49  const std::string& wildcard = "?" ) :
50  address_ ( address ),
51  wildcard_ ( wildcard ) {
52  };
53 
59  inline const std::string get ( T idx ) {
60  std::string tmpaddress = address_;
61  LDEBUG ( "Parsing [" << tmpaddress << "]=>" << idx );
62  parse ( idx, tmpaddress );
63  return tmpaddress;
64  }
65 
72  inline const std::string operator() ( T idx ) {
73  return get ( idx );
74  }
75 
81  inline const std::string operator() () {
82  return address_;
83  }
84 
85  private:
91  inline void parse ( T idx, std::string& tmpaddress ) {
92  find_and_replace ( tmpaddress, wildcard_, toString<T> ( idx ) );
93  };
94 
95 };
96 
98 
99 }
100 } // end namespaces
101 
102 #endif
class that expands a wildcard into its actual value. This is useful e.g. for filenames ranging severa...
#define LDEBUG(msg)
const std::string operator()()
Returns original string, without replacing any wildcard.
PatternAddress(const std::string &address, const std::string &wildcard="?")
Constructor.
PatternAddress< uint > IntegerPatternAddress
void find_and_replace(std::string &haystack, const std::string &needle, const std::string &replace)
Definition: bleu.hpp:14