Homepage Demos Overview Downloads Tutorials Reference
Credits

WMclass.cc

Go to the documentation of this file.
00001 // Watchable Memory (WM)
00002 //
00003 // David S. Touretzky
00004 // (Insert standard Tekkotsu copyright stuff here.)
00005 
00006 #include "WMclass.h"
00007 
00008 //================================================================
00009 //
00010 // toString() methods for various classes
00011 //
00012 
00013 template<>
00014 std::string WMitem<int>::toString(void) const {
00015   char print_buffer[30];
00016   sprintf(print_buffer,"%d",get_value());
00017   return std::string(print_buffer);
00018 }
00019 
00020 template<>
00021 std::string WMitem<float>::toString(void) const {
00022   char print_buffer[30];
00023   sprintf(print_buffer,"%g",get_value());
00024   return std::string(print_buffer);
00025 }
00026 
00027 template<>
00028 std::string WMitem<double>::toString(void) const {
00029   char print_buffer[30];
00030   sprintf(print_buffer,"%g",get_value());
00031   return std::string(print_buffer);
00032 }
00033 
00034 template<>
00035 std::string WMitem<bool>::toString(void) const {
00036   char print_buffer[30];
00037   sprintf(print_buffer,"%d",get_value());
00038   return std::string(print_buffer);
00039 }
00040 
00041 template<>
00042 std::string WMitem<char>::toString(void) const {
00043   char print_buffer[30];
00044   sprintf(print_buffer,"'%c'",get_value());
00045   return std::string(print_buffer);
00046 }
00047 
00048 template<>
00049 std::string WMitem<char*>::toString(void) const {
00050   char buff[1+WM_max_stringlen] = "";
00051   strncpy(buff,get_value(),WM_max_stringlen);
00052   char *p = get_value();
00053   char *q = p + WM_max_stringlen + 1;
00054   for (; p != q ; p++)
00055     if ( *p == 0 ) break;
00056   std::string result = std::string("\"") + buff + ((p==q) ? "..." : "") + "\"";
00057   return result;
00058 }
00059 
00060 template<>
00061 std::string WMitem<std::string>::toString(void) const {
00062   return std::string("\"") + 
00063     ((get_value().length() <= WM_max_stringlen) ?
00064      get_value() : get_value().substr(0,WM_max_stringlen) + "...") + "\"";
00065 }
00066 
00067 template<>
00068 std::string WMitem<WMregistry>::toString(void) const {
00069   char print_buffer[300];
00070   sprintf(print_buffer,"<%s, %d entries>",
00071     get_value().name.data(),get_value().entries.size());
00072   return std::string(print_buffer);
00073 }
00074 
00075 WMregistry GlobalWM("GlobalWM");
00076 
00077 WMitem<WMregistry> lookup_reg(std::string const &name, WMregistry &registry) {
00078   for (std::vector<WMentry*>::const_iterator it = registry.entries.begin(); 
00079        it != registry.entries.end(); it++) {
00080     if ( (*it)->item_name == name )
00081       return *static_cast<WMitem<WMregistry> const*>((*it)->item);
00082   };
00083   return create_WMentry(name, "WMregistry", new WMregistry(name, &registry),
00084                         registry);
00085 }
00086 
00087 void WMregistry::dump(void) const {
00088   std::cout << std::endl << "Registry " << name << ":" << std::endl;
00089   for (std::vector<WMentry*>::const_iterator it = entries.begin();
00090        it != entries.end();
00091        it++)
00092     std::cout << "  " << (*it)->type_name << " " << (*it)->item_name
00093    << " = " << (*it)->item->toString() << std::endl;
00094 }
00095 
00096 void dump(WMitem<WMregistry> const &wmreg) {
00097   wmreg.get_value().dump();
00098 }

Tekkotsu v2.1
Generated Tue Mar 16 23:19:16 2004 by Doxygen 1.3.5