37 #ifndef RERANKER_ENVIRONMENT_IMPL_H_ 
   38 #define RERANKER_ENVIRONMENT_IMPL_H_ 
   42 #include <unordered_map> 
   43 #include <unordered_set> 
   50 using std::ostringstream;
 
   52 using std::unordered_map;
 
   53 using std::unordered_set;
 
   69     for (unordered_map<string, VarMapBase *>::iterator it = var_map_.begin();
 
   70          it != var_map_.end(); ++it) {
 
   77   virtual bool Defined(
const string &varname)
 const {
 
   78     unordered_map<string, string>::const_iterator it = types_.find(varname);
 
   79     return it != types_.end();
 
   87   virtual const string &
GetType(
const string &varname)
 const {
 
   88     unordered_map<string, string>::const_iterator type_it =
 
   90     if (type_it == types_.end()) {
 
   93     return type_it->second;
 
  102     string lookup_type = type;
 
  105     unordered_map<string, string>::const_iterator factory_type_it =
 
  106         concrete_to_factory_type_.find(type);
 
  107     if (factory_type_it != concrete_to_factory_type_.end()) {
 
  108       lookup_type = factory_type_it->second;
 
  111     unordered_map<string, VarMapBase *>::const_iterator var_map_it =
 
  112         var_map_.find(lookup_type);
 
  113     if (var_map_it == var_map_.end()) {
 
  116     return var_map_it->second;
 
  120   virtual void Print(ostream &os)
 const {
 
  121     for (unordered_map<string, VarMapBase *>::const_iterator var_map_it =
 
  123          var_map_it != var_map_.end(); ++var_map_it) {
 
  124       var_map_it->second->Print(os);
 
  135     for (unordered_map<string, VarMapBase *>::iterator new_env_var_map_it =
 
  136              new_env->var_map_.begin();
 
  137          new_env_var_map_it != new_env->var_map_.end(); ++new_env_var_map_it) {
 
  138       new_env_var_map_it->second = new_env_var_map_it->second->Copy(new_env);
 
  152   bool Get(
const string &varname, T *value) 
const;
 
  156   string InferType(
const string &varname,
 
  158                    bool *is_object_type);
 
  161   unordered_map<string, string> types_;
 
  165   unordered_map<string, VarMapBase *> var_map_;
 
  169   unordered_map<string, string> concrete_to_factory_type_;
 
  177   unordered_map<string, string>::const_iterator type_it =
 
  178       types_.find(varname);
 
  179   if (type_it == types_.end()) {
 
  181       ostringstream err_ss;
 
  182       err_ss << 
"Environment::Get: error: no value for variable " 
  184       cerr << err_ss.str() << endl;
 
  190   const string &type = type_it->second;
 
  191   unordered_map<string, VarMapBase*>::const_iterator var_map_it =
 
  194   if (var_map_it == var_map_.end()) {
 
  195     ostringstream err_ss;
 
  196     err_ss << 
"Environment::Get: error: types_ and var_map_ data members " 
  197            << 
"are out of sync";
 
  198     throw std::runtime_error(err_ss.str());
 
  205   if (typed_var_map == NULL) {
 
  206     ostringstream err_ss;
 
  207     err_ss << 
"Environment::Get: error: no value for variable " 
  208            << varname << 
" of type " << 
typeid(*value).name()
 
  209            << 
"; perhaps you meant " << type << 
"?";
 
  210     cerr << err_ss.str() << endl;
 
  213   bool success = typed_var_map->
Get(varname, value);
 
  215     ostringstream err_ss;
 
  216     err_ss << 
"Environment::Get: error: no value for variable " 
  217            << varname << 
" of type " << 
typeid(*value).name()
 
  218            << 
"; types_ and var_map_ data members are out of sync";
 
  219     throw std::runtime_error(err_ss.str());
 
A container to hold the mapping between named variables of a specific type and their values...
 
A simple class for tokenizing a stream of tokens for the formally specified language used to construc...
 
virtual void ReadAndSet(const string &varname, StreamTokenizer &st, const string type)
Sets the specified variable to the value obtained from the following tokens available from the specif...
 
bool Get(const string &varname, T *value) const 
Assigns the value of the specified variable to the object pointed to by the value parameter...
 
virtual ~EnvironmentImpl()
Destroys this environment. 
 
A base class for a mapping from variables of a specific type to their values. 
 
virtual void PrintFactories(ostream &os) const 
Prints out a human-readable string with the names of all abstract base types and their concrete imple...
 
virtual const string & GetType(const string &varname) const 
Retrieves the type name of the specified variable. 
 
Provides an interface for an Environment, which contains a map from variables of a specific type (pri...
 
virtual void Print(ostream &os) const 
Prints a human-readable string of all the variables in this environment, their types and...
 
virtual Environment * Copy() const 
Returns a copy of this environment. 
 
EnvironmentImpl(int debug=0)
Constructs a new, empty environment. 
 
bool Get(const string &varname, T *value) const 
Retrieves the value of the variable with the specified name and puts into into the object pointed to ...
 
Provides a set of named variables and their types, as well as the values for those variables...
 
An interface for an environment in which variables of various types are mapped to their values...
 
virtual VarMapBase * GetVarMap(const string &varname)
Retrieves the VarMap instance for the specified variable. 
 
virtual VarMapBase * GetVarMapForType(const string &type)
Retrieves the VarMap instance for the specified type. 
 
virtual bool Defined(const string &varname) const 
Returns whether the specified variable has been defined in this environment.