Home | History | Annotate | Download | only in script
      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 (at) google.com (Jake Ratkiewicz)
     16 
     17 #ifndef FST_SCRIPT_DRAW_H_
     18 #define FST_SCRIPT_DRAW_H_
     19 
     20 #include <fst/script/arg-packs.h>
     21 #include <fst/script/fst-class.h>
     22 #include <fst/script/draw-impl.h>
     23 #include <iostream>
     24 #include <fstream>
     25 
     26 namespace fst {
     27 namespace script {
     28 
     29 // Note: it is safe to pass these strings as references because
     30 // this struct is only used to pass them deeper in the call graph.
     31 // Be sure you understand why this is so before using this struct
     32 // for anything else!
     33 struct FstDrawerArgs {
     34   const FstClass &fst;
     35   const SymbolTable *isyms;
     36   const SymbolTable *osyms;
     37   const SymbolTable *ssyms;
     38   const bool accep;
     39   const string& title;
     40   const float width;
     41   const float height;
     42   const bool portrait;
     43   const bool vertical;
     44   const float ranksep;
     45   const float nodesep;
     46   const int fontsize;
     47   const int precision;
     48   const bool show_weight_one;
     49   ostream *ostrm;
     50   const string &dest;
     51 
     52   FstDrawerArgs(const FstClass &fst,
     53                 const SymbolTable *isyms,
     54                 const SymbolTable *osyms,
     55                 const SymbolTable *ssyms,
     56                 bool accep,
     57                 const string &title,
     58                 float width,
     59                 float height,
     60                 bool portrait,
     61                 bool vertical,
     62                 float ranksep,
     63                 float nodesep,
     64                 int fontsize,
     65                 int precision,
     66                 bool show_weight_one,
     67                 ostream *ostrm,
     68                 const string &dest) :
     69       fst(fst), isyms(isyms), osyms(osyms), ssyms(ssyms), accep(accep),
     70       title(title), width(width), height(height), portrait(portrait),
     71       vertical(vertical), ranksep(ranksep), nodesep(nodesep),
     72       fontsize(fontsize), precision(precision),
     73       show_weight_one(show_weight_one), ostrm(ostrm), dest(dest) { }
     74 };
     75 
     76 
     77 template<class Arc>
     78 void DrawFst(FstDrawerArgs *args) {
     79   const Fst<Arc> &fst = *(args->fst.GetFst<Arc>());
     80 
     81   FstDrawer<Arc> fstdrawer(fst, args->isyms, args->osyms, args->ssyms,
     82                            args->accep, args->title, args->width,
     83                            args->height, args->portrait,
     84                            args->vertical, args->ranksep,
     85                            args->nodesep, args->fontsize,
     86                            args->precision, args->show_weight_one);
     87   fstdrawer.Draw(args->ostrm, args->dest);
     88 }
     89 
     90 void DrawFst(const FstClass &fst,
     91              const SymbolTable *isyms,
     92              const SymbolTable *osyms,
     93              const SymbolTable *ssyms,
     94              bool accep,
     95              const string &title,
     96              float width,
     97              float height,
     98              bool portrait,
     99              bool vertical,
    100              float ranksep,
    101              float nodesep,
    102              int fontsize,
    103              int precision,
    104              bool show_weight_one,
    105              ostream *ostrm,
    106              const string &dest);
    107 
    108 }  // namespace script
    109 }  // namespace fst
    110 
    111 
    112 
    113 #endif  // FST_SCRIPT_DRAW_H_
    114