ESLA
Embeddable Scriting LAnguage
Stanford University, Rock Fracture Project research group
© 2003
00001 /************************************************************************* 00002 * ESLA: Embeddable Scripting LAnguage 00003 * Copyright (C) 2003 Frantz Maerten 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License as 00007 * published by the Free Software Foundation; either version 2 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * If you modify this software, you should contact the author, include 00011 * a notice giving the name of the person performing the modification, 00012 * the date of modification, and the reason for such modification. 00013 * 00014 * Note that the GNU General Public License does not permit 00015 * incorporating the Software into proprietary programs. 00016 * 00017 * Contact: Frantz Maerten 00018 * frantz@pangea.stanford.edu 00019 * 00020 * Dept. of Geological & Environmental Sciences 00021 * Stanford University 00022 * Stanford, CA 94305-2115 00023 * USA 00024 * 00025 * Adapted from Bruno Levy (levy@loria.fr) 00026 *************************************************************************/ 00027 00028 00029 #ifndef _NAMING_NAMING_CONTEXT__ 00030 #define _NAMING_NAMING_CONTEXT__ 00031 00032 #include "../esla_namespace.h" 00033 #include "gen_object.h" 00034 #include <string> 00035 #include <vector> 00036 #include "name.h" 00037 00038 //------------------------------------------------------ 00039 00040 BEGIN_LIB_NAMESPACE 00041 00042 class NamingContext : public GenObject { 00043 typedef const std::string& str_arg ; 00044 public: 00045 typedef std::string NameComponent ; 00046 typedef std::string ClassNameComponent ; 00047 00048 struct Binding { 00049 NameComponent binding_name ; 00050 ClassNameComponent binding_class_name ; 00051 GenObject* binded ; 00052 enum { 00053 CONTEXT, 00054 OBJECT 00055 } binding_type ; 00056 00057 }; 00058 00059 typedef std::vector<Binding> BindingList ; 00060 00061 NamingContext(); 00062 virtual ~NamingContext(); 00063 00064 virtual bool bind(const Name& name, GenObject* object); 00065 virtual GenObject* resolve(const Name& name) const; 00066 virtual NamingContext* resolve_context(const Name& name) const; 00067 virtual NamingContext* resolve_context(str_arg name) const; 00068 virtual NamingContext* bind_new_context(const Name& name); 00069 virtual NamingContext* new_context() const; 00070 00072 virtual ClassNameComponent context(GenObject* object) const ; 00073 00074 virtual bool is_binded(const Name& name) const ; 00075 virtual void list(BindingList& bindings) const ; 00076 void binded(std::vector<std::string>& list) const ; 00077 00078 bool unbind(const Name& name) ; 00079 00080 protected: 00081 BindingList bindings_; 00082 friend class NamingLibrary ; 00083 00084 void eat_one_name_component( const Name& name_in, Name& name_out) const; 00085 Binding& new_binding(); 00086 NamingContext* find_context_from_component( 00087 const NameComponent& name ) const; 00088 Binding* find_binding_from_component( const NameComponent& name ) const; 00089 Binding* find_binding_from_name(const Name& name) const; 00090 00091 } ; 00092 00093 00094 END_LIB_NAMESPACE 00095 00096 #endif 00097 00098