FST  openfst-1.8.3
OpenFst Library
concat.h
Go to the documentation of this file.
1 // Copyright 2005-2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 
18 #ifndef FST_SCRIPT_CONCAT_H_
19 #define FST_SCRIPT_CONCAT_H_
20 
21 #include <utility>
22 #include <vector>
23 
24 #include <fst/concat.h>
25 #include <fst/fst.h>
26 #include <fst/mutable-fst.h>
27 #include <fst/script/fst-class.h>
28 
29 namespace fst {
30 namespace script {
31 
32 using FstConcatArgs1 = std::pair<MutableFstClass *, const FstClass &>;
33 
34 template <class Arc>
35 void Concat(FstConcatArgs1 *args) {
36  MutableFst<Arc> *fst1 = std::get<0>(*args)->GetMutableFst<Arc>();
37  const Fst<Arc> &fst2 = *std::get<1>(*args).GetFst<Arc>();
38  Concat(fst1, fst2);
39 }
40 
41 using FstConcatArgs2 = std::pair<const FstClass &, MutableFstClass *>;
42 
43 template <class Arc>
44 void Concat(FstConcatArgs2 *args) {
45  const Fst<Arc> &fst1 = *std::get<0>(*args).GetFst<Arc>();
46  MutableFst<Arc> *fst2 = std::get<1>(*args)->GetMutableFst<Arc>();
47  Concat(fst1, fst2);
48 }
49 
50 using FstConcatArgs3 =
51  std::pair<const std::vector<FstClass *> &, MutableFstClass *>;
52 
53 template <class Arc>
54 void Concat(FstConcatArgs3 *args) {
55  const auto &untyped_fsts1 = std::get<0>(*args);
56  std::vector<const Fst<Arc> *> typed_fsts1;
57  typed_fsts1.reserve(untyped_fsts1.size());
58  for (const auto &untyped_fst1 : untyped_fsts1) {
59  typed_fsts1.emplace_back(untyped_fst1->GetFst<Arc>());
60  }
61  MutableFst<Arc> *fst2 = std::get<1>(*args)->GetMutableFst<Arc>();
62  Concat(typed_fsts1, fst2);
63 }
64 
65 void Concat(MutableFstClass *fst1, const FstClass &fst2);
66 
67 void Concat(const FstClass &fst1, MutableFstClass *fst2);
68 
69 void Concat(const std::vector<FstClass *> &fsts1, MutableFstClass *fst2);
70 
71 } // namespace script
72 } // namespace fst
73 
74 #endif // FST_SCRIPT_CONCAT_H_
std::pair< MutableFstClass *, const FstClass & > FstConcatArgs1
Definition: concat.h:32
std::pair< const std::vector< FstClass * > &, MutableFstClass * > FstConcatArgs3
Definition: concat.h:51
std::pair< const FstClass &, MutableFstClass * > FstConcatArgs2
Definition: concat.h:41
void Concat(FstConcatArgs1 *args)
Definition: concat.h:35