1
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6//     http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13//
14// Copyright 2005-2010 Google, Inc.
15// Author: jpr@google.com (Jake Ratkiewicz)
16
17#ifndef FST_SCRIPT_PRINT_H_
18#define FST_SCRIPT_PRINT_H_
19
20#include <fst/script/arg-packs.h>
21#include <fst/script/fst-class.h>
22#include <fst/script/print-impl.h>
23
24namespace fst {
25namespace script {
26
27// Note: it is safe to pass these strings as references because
28// this struct is only used to pass them deeper in the call graph.
29// Be sure you understand why this is so before using this struct
30// for anything else!
31struct FstPrinterArgs {
32  const FstClass &fst;
33  const SymbolTable *isyms;
34  const SymbolTable *osyms;
35  const SymbolTable *ssyms;
36  const bool accept;
37  const bool show_weight_one;
38  ostream *ostrm;
39  const string &dest;
40
41  FstPrinterArgs(const FstClass &fst,
42                 const SymbolTable *isyms,
43                 const SymbolTable *osyms,
44                 const SymbolTable *ssyms,
45                 bool accept,
46                 bool show_weight_one,
47                 ostream *ostrm,
48                 const string &dest) :
49      fst(fst), isyms(isyms), osyms(osyms), ssyms(ssyms), accept(accept),
50      show_weight_one(show_weight_one), ostrm(ostrm), dest(dest) { }
51};
52
53template<class Arc>
54void PrintFst(FstPrinterArgs *args) {
55  const Fst<Arc> &fst = *(args->fst.GetFst<Arc>());
56
57  fst::FstPrinter<Arc> fstprinter(fst, args->isyms, args->osyms,
58                                      args->ssyms, args->accept,
59                                      args->show_weight_one);
60  fstprinter.Print(args->ostrm, args->dest);
61}
62
63void PrintFst(const FstClass &fst, ostream &ostrm, const string &dest,
64              const SymbolTable *isyms,
65              const SymbolTable *osyms,
66              const SymbolTable *ssyms,
67              bool accept, bool show_weight_one);
68
69
70// Below are two printing methods with useful defaults for a few of
71// the fst printer arguments.
72template <class Arc>
73void PrintFst(const Fst<Arc> &fst, ostream &os, const string dest = "",
74              const SymbolTable *isyms = NULL,
75              const SymbolTable *osyms = NULL,
76              const SymbolTable *ssyms = NULL) {
77  fst::FstPrinter<Arc> fstprinter(fst, isyms, osyms, ssyms, true, true);
78  fstprinter.Print(&os, dest);
79}
80
81}  // namespace script
82}  // namespace fst
83
84
85
86#endif  // FST_SCRIPT_PRINT_H_
87