StdTagBase.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <servlet/taglib/CompileTimeTaglib.h>
00022 #include <servlet/taglib/Generator.h>
00023 #include <stdexcept>
00024 #include <set>
00025 #include <vector>
00026 #include <iterator>
00027 #include <string.h>
00028 #include <algorithm>
00029
00030 namespace csp
00031 {
00032 namespace tags
00033 {
00034
00035
00038 class StdTagBase: public servlet::taglib::Generator
00039 {
00040 protected:
00041 StdTagBase(const std::string& name)
00042 : Generator(name)
00043 {}
00044 protected:
00045 static bool common_headers_included;
00046 static const char illegal[];
00047 static void get_attr(const Generator::attribs_t& attribs, const std::string& name,
00048 std::string& dest, const std::string& tag, const std::string& default_val = std::string())
00049 {
00050 attribs_t::const_iterator it = attribs.find(name);
00051 if(it!=attribs.end())
00052 dest=it->second;
00053 else if(!default_val.empty())
00054 dest = default_val;
00055 else
00056 throw std::runtime_error(tag +" requires attribute "+name);
00057 }
00058
00059 static bool get_bool_attr(const Generator::attribs_t& attribs, const std::string& name,
00060 const std::string& tag, const std::string& def_val="false")
00061 {
00062 std::string val;
00063 get_attr(attribs, name, val, tag, def_val);
00064 std::transform(val.begin(), val.end(), val.begin(), ::tolower);
00065 if(val=="true" || val=="yes" || val=="1")
00066 return true;
00067 return false;
00068 }
00069
00070
00071
00072 static char to_cxx_ident(char c)
00073 {
00074 for(unsigned i = 0; i < ::strlen(illegal)-1; i++)
00075 if(c==illegal[i])
00076 return '_';
00077 return c;
00078 }
00079 };
00080
00081 }
00082 }
00083
00084