40#include "ling_class/EST_Item.h"
41#include "ling_class/EST_FeatureFunctionPackage.h"
42#include "EST_FeatureFunctionContext.h"
44#include "ling_class_init.h"
46void EST_FeatureFunctionContext::class_init(
void)
48 ling_class_init::use();
50 global =
new EST_FeatureFunctionContext();
55const EST_String EST_FeatureFunctionContext::separator =
"+";
57EST_FeatureFunctionContext::EST_FeatureFunctionContext(
void)
62EST_FeatureFunctionContext::~EST_FeatureFunctionContext(
void)
64 EST_TList<EST_FeatureFunctionPackage *>::RwEntries p;
66 for(p.
begin(packages); p; ++p)
77 EST_TList<EST_FeatureFunctionPackage *>::Entries p;
79 for(p.
begin(packages); p; ++p)
81 EST_FeatureFunctionPackage *
package = *p;
82 if (package->name() == name)
88EST_String EST_FeatureFunctionContext::get_featfunc_name(
const EST_Item_featfunc func,
int &found)
const
90 EST_TList<EST_FeatureFunctionPackage *>::Entries p;
94 for(p.
begin(packages); p; ++p)
96 EST_FeatureFunctionPackage *
package = *p;
98 EST_String name = package->lookup(func, found);
111void EST_FeatureFunctionContext::clear_cache(
void)
116void EST_FeatureFunctionContext::add_package(
const EST_String name)
119 EST_error(
"Attempt to add package '%s' to global list",
123 EST_FeatureFunctionPackage *
package = global->get_package(name);
126 EST_error(
"package '%s' not loaded",
130 packages.prepend(package);
135void EST_FeatureFunctionContext::add_package(EST_FeatureFunctionPackage *package)
137 packages.prepend(package);
142bool EST_FeatureFunctionContext::package_included(
const EST_String name)
const
144 return get_package(name) != NULL;
147const EST_Item_featfunc EST_FeatureFunctionContext::get_featfunc(
const EST_String name,
153 if (cache.present(name))
154 return cache.val(name);
156 if ((pos= name.
search(separator, len, 0))>=0)
158 const EST_Item_featfunc func2 =
159 get_featfunc(name.
before(pos,separator.length()),
160 name.
after(pos,separator.length()), must);
163 cache.add_item(name, func2);
169 EST_TList<EST_FeatureFunctionPackage *>::Entries p;
171 for(p.
begin(packages); p; ++p)
173 EST_FeatureFunctionPackage *
package = *p;
177 const EST_FeatureFunctionPackage::Entry &ent = package->lookup(name, found);
181 cache.add_item(name, ent.func);
187 EST_error(
"No feature function '%s'", (
const char *)name);
192const EST_Item_featfunc EST_FeatureFunctionContext::get_featfunc(
const EST_String pname,
193 const EST_String name,
196 EST_FeatureFunctionPackage *
package = get_package(pname);
200 const EST_FeatureFunctionPackage::Entry &ent =
201 package->lookup(name, found);
207 EST_error(
"No feature function '%s'", (
const char *)name);
212static EST_Val Dummy_Func(EST_Item *) {
return EST_Val(); }
213template <> EST_String
214EST_THash<EST_String, EST_Item_featfunc>::Dummy_Key =
"DUMMY";
215template <> EST_Item_featfunc
216EST_THash<EST_String, EST_Item_featfunc>::Dummy_Value = Dummy_Func;
217Declare_TList_T(EST_FeatureFunctionPackage *, EST_FeatureFunctionPackageP)
220#if defined(INSTANTIATE_TEMPLATES)
222#include "../base_class/EST_THash.cc"
224Instantiate_TStringHash(EST_Item_featfunc)
226#include "../base_class/EST_TList.cc"
227Instantiate_TList_T(EST_FeatureFunctionPackage *, EST_FeatureFunctionPackageP)
EST_String before(int pos, int len=0) const
Part before position.
static EST_String cat(const EST_String s1, const EST_String s2=Empty, const EST_String s3=Empty, const EST_String s4=Empty, const EST_String s5=Empty, const EST_String s6=Empty, const EST_String s7=Empty, const EST_String s8=Empty, const EST_String s9=Empty)
int search(const char *s, int len, int &mlen, int pos=0) const
Find a substring.
EST_String after(int pos, int len=1) const
Part after pos+len.
void begin(const Container &over)
Set the iterator ready to run over this container.
void begin(Container &over)
Set the iterator ready to run over this container.