1f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
2f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Licensed under the Apache License, Version 2.0 (the "License");
3f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// you may not use this file except in compliance with the License.
4f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// You may obtain a copy of the License at
5f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
6f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//     http://www.apache.org/licenses/LICENSE-2.0
7f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
8f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Unless required by applicable law or agreed to in writing, software
9f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// distributed under the License is distributed on an "AS IS" BASIS,
10f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// See the License for the specific language governing permissions and
12f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// limitations under the License.
13f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
14f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Copyright 2005-2010 Google, Inc.
15f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Author: jpr@google.com (Jake Ratkiewicz)
16f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
17f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Represents a generic weight in an FST -- that is, represents a specific
18f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// type of weight underneath while hiding that type from a client.
19f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
20f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
21f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#ifndef FST_SCRIPT_WEIGHT_CLASS_H_
22f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#define FST_SCRIPT_WEIGHT_CLASS_H_
23f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
24f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <string>
25f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
26f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/generic-register.h>
27f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#include <fst/util.h>
28f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
29f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonnamespace fst {
30f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonnamespace script {
31f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
32f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonclass WeightImplBase {
33f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson public:
34f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual WeightImplBase *Copy() const = 0;
35f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual void Print(ostream *o) const = 0;
36f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual const string &Type() const = 0;
37f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual string to_string() const = 0;
38f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual bool operator == (const WeightImplBase &other) const = 0;
39f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual ~WeightImplBase() { }
40f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson};
41f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
42f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontemplate<class W>
43f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonstruct WeightClassImpl : public WeightImplBase {
44f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  W weight;
45f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
46f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  explicit WeightClassImpl(const W& weight) : weight(weight) { }
47f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
48f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual WeightClassImpl<W> *Copy() const {
49f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return new WeightClassImpl<W>(weight);
50f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
51f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
52f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual const string &Type() const { return W::Type(); }
53f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
54f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual void Print(ostream *o) const {
55f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    *o << weight;
56f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
57f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
58f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual string to_string() const {
59dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin    string str;
60dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin    WeightToStr(weight, &str);
61dfd8b8327b93660601d016cdc6f29f433b45a8d8Alexander Gutkin    return str;
62f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
63f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
64f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual bool operator == (const WeightImplBase &other) const {
65f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    if (Type() != other.Type()) {
66f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      return false;
67f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    } else {
68f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      const WeightClassImpl<W> *typed_other =
69f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson          static_cast<const WeightClassImpl<W> *>(&other);
70f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
71f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      return typed_other->weight == weight;
72f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    }
73f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
74f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson};
75f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
76f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
77f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonclass WeightClass {
78f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson public:
79f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  WeightClass() : element_type_(ZERO), impl_(0) { }
80f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
81f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  template<class W>
82f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  explicit WeightClass(const W& weight)
83f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  : element_type_(OTHER), impl_(new WeightClassImpl<W>(weight)) { }
84f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
85f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  WeightClass(const string &weight_type, const string &weight_str);
86f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
87f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  WeightClass(const WeightClass &other) :
88f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      element_type_(other.element_type_),
89f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      impl_(other.impl_ ? other.impl_->Copy() : 0) { }
90f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
91f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  WeightClass &operator = (const WeightClass &other) {
92f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    if (impl_) delete impl_;
93f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    impl_ = other.impl_ ? other.impl_->Copy() : 0;
94f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    element_type_ = other.element_type_;
95f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return *this;
96f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
97f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
98f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  template<class W>
99f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  const W* GetWeight() const;
100f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
101f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  string to_string() const {
102f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    switch (element_type_) {
103f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      case ZERO:
104f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson        return "ZERO";
105f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      case ONE:
106f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson        return "ONE";
107f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      default:
108f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      case OTHER:
109f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson        return impl_->to_string();
110f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    }
111f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
112f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
113f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  bool operator == (const WeightClass &other) const {
114f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return element_type_ == other.element_type_ &&
115f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson        ((impl_ && other.impl_ && (*impl_ == *other.impl_)) ||
116f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson         (impl_ == 0 && other.impl_ == 0));
117f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
118f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
119f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  static const WeightClass &Zero() {
120f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    static WeightClass w(ZERO);
121f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
122f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return w;
123f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
124f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
125f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  static const WeightClass &One() {
126f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    static WeightClass w(ONE);
127f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
128f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return w;
129f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
130f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
1315b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin  const string &Type() const {
1325b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin    if (impl_) return impl_->Type();
1335b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin    static const string no_type = "none";
1345b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin    return no_type;
1355b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin  }
1365b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin
1375b6dc79427b8f7eeb6a7ff68034ab8548ce670eaAlexander Gutkin
138f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  ~WeightClass() { if (impl_) delete impl_; }
139f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson private:
140f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  enum ElementType { ZERO, ONE, OTHER };
141f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  ElementType element_type_;
142f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
143f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  WeightImplBase *impl_;
144f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
145f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  explicit WeightClass(ElementType et) : element_type_(et), impl_(0) { }
146f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
147f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  friend ostream &operator << (ostream &o, const WeightClass &c);
148f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson};
149f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
150f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontemplate<class W>
151f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonconst W* WeightClass::GetWeight() const {
152f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  // We need to store zero and one as statics, because the weight type
153f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  // W might return them as temporaries. We're returning a pointer,
154f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  // and it won't do to get the address of a temporary.
155f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  static const W zero = W::Zero();
156f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  static const W one = W::One();
157f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
158f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  if (element_type_ == ZERO) {
159f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return &zero;
160f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  } else if (element_type_ == ONE) {
161f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return &one;
162f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  } else {
163f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    if (W::Type() != impl_->Type()) {
164f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      return NULL;
165f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    } else {
166f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      WeightClassImpl<W> *typed_impl =
167f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson          static_cast<WeightClassImpl<W> *>(impl_);
168f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      return &typed_impl->weight;
169f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    }
170f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
171f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}
172f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
173f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
174f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Registration for generic weight types.
175f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
176f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
177f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontypedef WeightImplBase* (*StrToWeightImplBaseT)(const string &str,
178f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                                                const string &src,
179f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                                                size_t nline);
180f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
181f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontemplate<class W>
182f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian HodsonWeightImplBase* StrToWeightImplBase(const string &str,
183f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                                    const string &src, size_t nline) {
184f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  return new WeightClassImpl<W>(StrToWeight<W>(str, src, nline));
185f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}
186f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
187f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// The following confuses swig, and doesn't need to be wrapped anyway.
188f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#ifndef SWIG
189f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonostream& operator << (ostream &o, const WeightClass &c);
190f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
191f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsonclass WeightClassRegister : public GenericRegister<string,
192f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                                                   StrToWeightImplBaseT,
193f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson                                                   WeightClassRegister> {
194f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson protected:
195f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  virtual string ConvertKeyToSoFilename(const string &key) const {
196f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson    return key + ".so";
197f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  }
198f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson};
199f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
200f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodsontypedef GenericRegisterer<WeightClassRegister> WeightClassRegisterer;
201f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#endif
202f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
203f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// internal version, needs to be called by wrapper in order for
204f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// macro args to expand
205f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#define REGISTER_FST_WEIGHT__(Weight, line)                             \
206f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  static WeightClassRegisterer weight_registerer ## _ ## line(          \
207f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      Weight::Type(),                                                   \
208f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson      StrToWeightImplBase<Weight>)
209f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
210f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// This layer is where __FILE__ and __LINE__ are expanded
211f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#define REGISTER_FST_WEIGHT_EXPANDER(Weight, line)      \
212f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  REGISTER_FST_WEIGHT__(Weight, line)
213f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
214f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
215f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson// Macro for registering new weight types. Clients call this.
216f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson//
217f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#define REGISTER_FST_WEIGHT(Weight) \
218f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson  REGISTER_FST_WEIGHT_EXPANDER(Weight, __LINE__)
219f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
220f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}  // namespace script
221f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson}  // namespace fst
222f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson
223f4c12fce1ee58e670f9c3fce46c40296ba9ee8a2Ian Hodson#endif  // FST_SCRIPT_WEIGHT_CLASS_H_
224