encode.h revision f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2
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_ENCODE_H_ 18#define FST_SCRIPT_ENCODE_H_ 19 20#include <string> 21 22#include <fst/script/arg-packs.h> 23#include <fst/script/fst-class.h> 24#include <fst/encode.h> 25 26namespace fst { 27namespace script { 28 29typedef args::Package<MutableFstClass*, uint32, bool, 30 const string &> EncodeArgs; 31 32template<class Arc> 33void Encode(EncodeArgs *args) { 34 MutableFst<Arc> *ofst = args->arg1->GetMutableFst<Arc>(); 35 bool reuse_encoder = args->arg3; 36 const string &coder_fname = args->arg4; 37 uint32 flags = args->arg2; 38 39 EncodeMapper<Arc> *encoder = reuse_encoder 40 ? EncodeMapper<Arc>::Read(coder_fname, ENCODE) 41 : new EncodeMapper<Arc>(flags, ENCODE); 42 43 Encode(ofst, encoder); 44 if (!args->arg3) 45 encoder->Write(coder_fname); 46 47 delete encoder; 48} 49 50void Encode(MutableFstClass *fst, uint32 flags, bool reuse_encoder, 51 const string &coder_fname); 52 53} // namespace script 54} // namespace fst 55 56 57 58#endif // FST_SCRIPT_ENCODE_H_ 59