CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

StdTagBase.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2009 by Ilya A. Volynets-Evenbakh                  *
00003  *   ilya@total-knowledge.com                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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 //FIXME: this is hackish, since there could be multiple
00071 //FIXME:    attribute names which map to the same identifier
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 } // namespace tags
00082 } // namespace csp
00083 
00084 /* -*- c++ -*- */

SourceForge.net Logo