Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
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 #ifndef __CYGWIN__
00014 
00015 template<>
00016 std::string WMitem<int>::toString(void) const {
00017   char print_buffer[30];
00018   sprintf(print_buffer,"%d",get_value());
00019   return std::string(print_buffer);
00020 }
00021 
00022 template<>
00023 std::string WMitem<float>::toString(void) const {
00024   char print_buffer[30];
00025   sprintf(print_buffer,"%g",get_value());
00026   return std::string(print_buffer);
00027 }
00028 
00029 template<>
00030 std::string WMitem<double>::toString(void) const {
00031   char print_buffer[30];
00032   sprintf(print_buffer,"%g",get_value());
00033   return std::string(print_buffer);
00034 }
00035 
00036 template<>
00037 std::string WMitem<bool>::toString(void) const {
00038   char print_buffer[30];
00039   sprintf(print_buffer,"%d",get_value());
00040   return std::string(print_buffer);
00041 }
00042 
00043 template<>
00044 std::string WMitem<char>::toString(void) const {
00045   char print_buffer[30];
00046   sprintf(print_buffer,"'%c'",get_value());
00047   return std::string(print_buffer);
00048 }
00049 
00050 template<>
00051 std::string WMitem<char*>::toString(void) const {
00052   char buff[1+WM_max_stringlen] = "";
00053   strncpy(buff,get_value(),WM_max_stringlen);
00054   char *p = get_value();
00055   char *q = p + WM_max_stringlen + 1;
00056   for (; p != q ; p++)
00057     if ( *p == 0 ) break;
00058   std::string result = std::string("\"") + buff + ((p==q) ? "..." : "") + "\"";
00059   return result;
00060 }
00061 
00062 template<>
00063 std::string WMitem<std::string>::toString(void) const {
00064   return std::string("\"") + 
00065     ((get_value().length() <= WM_max_stringlen) ?
00066      get_value() : get_value().substr(0,WM_max_stringlen) + "...") + "\"";
00067 }
00068 
00069 template<>
00070 std::string WMitem<WMregistry>::toString(void) const {
00071   char print_buffer[300];
00072   sprintf(print_buffer,"<%s, %lu entries>",
00073     get_value().name.data(),(unsigned long)get_value().entries.size());
00074   return std::string(print_buffer);
00075 }
00076 
00077 #endif //CYGWIN-compiler incompatable
00078 
00079 WMregistry GlobalWM("GlobalWM");
00080 
00081 WMitem<WMregistry> lookup_reg(std::string const &name, WMregistry &registry) {
00082   for (std::vector<WMentry*>::const_iterator it = registry.entries.begin(); 
00083        it != registry.entries.end(); it++) {
00084     if ( (*it)->item_name == name )
00085       return *static_cast<WMitem<WMregistry> const*>((*it)->item);
00086   };
00087   return create_WMentry(name, "WMregistry", new WMregistry(name, &registry),
00088                         registry);
00089 }
00090 
00091 void WMregistry::dump(void) const {
00092   std::cout << std::endl << "Registry " << name << ":" << std::endl;
00093   for (std::vector<WMentry*>::const_iterator it = entries.begin();
00094        it != entries.end();
00095        it++)
00096     std::cout << "  " << (*it)->type_name << " " << (*it)->item_name
00097    << " = " << (*it)->item->toString() << std::endl;
00098 }
00099 
00100 void dump(WMitem<WMregistry> const &wmreg) {
00101   wmreg.get_value().dump();
00102 }

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:53 2016 by Doxygen 1.6.3