Google
Web alhem.net

Link.cpp

Go to the documentation of this file.
00001 /*
00002  **     \file Link.cpp
00003  **     \date  2006-05-05
00004  **     \author grymse@alhem.net
00005 **/
00006 /*
00007 Copyright (C) 2006  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 #include "WebForm.h"
00024 #include "Link.h"
00025 #include "Web.h"
00026 
00027 
00028 namespace Cgi
00029 {
00030 
00031 
00032 Link::Link(WebForm *p, const std::string& action, const std::string& linktext)
00033 :Styled()
00034 ,m_webform(p)
00035 ,m_action(action)
00036 ,m_linktext(linktext)
00037 {
00038 }
00039 
00040 
00041 Link::~Link()
00042 {
00043         while (m_params.size())
00044         {
00045                 param_v::iterator it = m_params.begin();
00046                 Param *p = *it;
00047                 delete p;
00048                 m_params.erase(it);
00049         }
00050 }
00051 
00052 
00053 void Link::AddParam(const std::string& name)
00054 {
00055         m_params.push_back(new Param(name));
00056 }
00057 
00058 
00059 void Link::AddParam(const std::string& name,const std::string& value)
00060 {
00061         m_params.push_back(new Param2(name, value));
00062 }
00063 
00064 
00065 void Link::AddParam(const std::string& name,long value)
00066 {
00067         char slask[100];
00068         sprintf(slask, "%ld", value);
00069         m_params.push_back(new Param2(name, slask));
00070 }
00071 
00072 
00073 const std::string& Link::GetLink()
00074 {
00075         Web *web = m_webform -> GetWeb();
00076         char slask[1000];
00077         sprintf(slask, "<a");
00078         if (GetStyle().size())
00079         {
00080                 sprintf(slask + strlen(slask), " style='%s'", GetStyle().c_str());
00081         }
00082         sprintf(slask + strlen(slask), " href='%s?%s=%s", web -> GetCgiName().c_str(),
00083                 m_webform -> GetFormName().c_str(), m_action.c_str());
00084         for (param_v::iterator it = m_params.begin(); it != m_params.end(); it++)
00085         {
00086                 Param *p = *it;
00087                 strcat(slask, p -> Print().c_str());
00088         }
00089         sprintf(slask + strlen(slask), "'>%s</a>", m_linktext.c_str());
00090         m_link = slask;
00091         return m_link;
00092 }
00093 
00094 
00095 } // namespace Cgi
00096 
00097 

Generated for cgi++ by doxygen 1.3.7

Page, code, and content Copyright (C) 2004 by Anders Hedström