Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

aliaser.h

00001 #ifndef s11n_ALIASER_H_INCLUDED 00002 #define s11n_ALIASER_H_INCLUDED 1 00003 00004 #include <map> 00005 #include <string> 00006 00007 #include <s11n/debuggering_macros.h> // COUT/CERR 00008 #include <s11n/phoenix.h> // comes from libclass_loader 00009 00010 namespace s11n 00011 { 00012 /** 00013 aliaser is a helper class for mapping single-token aliases 00014 to arbitrary strings, e.g., similarly to typical Unix shell 00015 alias support. It is intended to be used in the creation 00016 of shell-like application interfaces, but may have uses 00017 elsewhere (e.g., aliases class names for class_loader<T>). 00018 */ 00019 class aliaser 00020 { 00021 public: 00022 /** 00023 The map used to store aliases. 00024 */ 00025 typedef std::map<std::string,std::string> map_type; 00026 00027 aliaser(); 00028 ~aliaser(); 00029 00030 /** 00031 Returns the map of aliases-to-expansions. 00032 */ 00033 map_type & map(); 00034 /** Const form of map(). */ 00035 const map_type & map() const; 00036 00037 /** 00038 A shared instance of this object. Not post-main() safe. 00039 */ 00040 static aliaser & instance(); 00041 00042 /** 00043 context() is used for getting a "context singleton" - an instance 00044 of this object which is a quasi-singleton within the given ContextType. 00045 */ 00046 template <typename ContextType> 00047 static aliaser & context() 00048 { 00049 return phoenix<aliaser,ContextType>::instance(); 00050 } 00051 00052 /** 00053 Aliases <code>al</code> as a shortcut for <code>expanded</code>. 00054 00055 al should be exactly one token. 00056 00057 If expanded is empty then any existing alias al is removed, and 00058 this is the way to unset an alias. 00059 */ 00060 void alias( const std::string & al, const std::string & expanded ); 00061 00062 /** 00063 Works similarly to Unix shells' alias expansion: 00064 00065 Expands the first input token as an alias. This 00066 expansion continues until the data can no longer be 00067 expanded to a new string. 00068 00069 It returns the expanded string, which may be identical 00070 to the input. 00071 */ 00072 std::string expand( const std::string & input ) const; 00073 00074 private: 00075 map_type m_map; 00076 }; 00077 00078 } // namespace s11n 00079 00080 #endif // s11n_ALIASER_H_INCLUDED

Generated on Tue Jul 20 10:46:47 2004 for s11n by doxygen 1.3.7