Skip to content

Commit

Permalink
Make std namespace explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Apr 13, 2024
1 parent 07091ee commit 63234fc
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 233 deletions.
17 changes: 8 additions & 9 deletions assets/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,45 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <assets/header.h>
#include <filter/url.h>
#include <config/globals.h>
using namespace std;


namespace assets_page {


string header (const string & title, Webserver_Request& webserver_request)
std::string header (const std::string& title, Webserver_Request& webserver_request)
{
Assets_Header header = Assets_Header (title, webserver_request);
string page = header.run ();
return page;
return header.run ();
}


string success (const string & message)
std::string success (const std::string& message)
{
Assets_View view {};
view.set_variable ("message", message);
return view.render ("assets", "success");
}


string error (const string & message)
std::string error (const std::string& message)
{
Assets_View view {};
view.set_variable ("message", message);
return view.render ("assets", "error");
}


string message (const string & message)
std::string message (const std::string& message)
{
Assets_View view {};
view.set_variable ("message", message);
return view.render ("assets", "message");
}


string footer ()
std::string footer ()
{
string page {};
std::string page {};
Assets_View view {};
page += view.render ("assets", "workspacewrapper_finish");
page += view.render ("assets", "footer");
Expand Down
22 changes: 10 additions & 12 deletions assets/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <config/globals.h>
#include <database/logs.h>
#include <flate/flate.h>
using namespace std;


Assets_View::Assets_View ()
Expand All @@ -38,26 +37,26 @@ Assets_View::Assets_View ()


// Sets a variable (key and value) for the html template.
void Assets_View::set_variable (string key, string value)
void Assets_View::set_variable (const std::string& key, const std::string& value)
{
m_variables[key] = value;
}


// Enable displaying a zone in the html template.
void Assets_View::enable_zone (string zone)
void Assets_View::enable_zone (const std::string& zone)
{
m_zones [zone] = true;
}


void Assets_View::disable_zone (string zone)
void Assets_View::disable_zone (const std::string& zone)
{
m_zones.erase (zone);
}


void Assets_View::add_iteration (string key, map <string, string> value)
void Assets_View::add_iteration (const std::string& key, const std::map <std::string, std::string>& value)
{
m_iterations[key].push_back (value);
}
Expand All @@ -69,32 +68,31 @@ void Assets_View::add_iteration (string key, map <string, string> value)
// 2: Basename of the html template without the .html extension.
// Setting the session variables in the template is postponed to the very last moment,
// since these could change during the course of the calling page.
string Assets_View::render (string tpl1, string tpl2)
std::string Assets_View::render (const std::string& tpl1, const std::string& tpl2)
{
// Variable tpl is a relative path. Make it a full one.
string tpl = filter_url_create_root_path ({tpl1, tpl2 + ".html"});
const std::string tpl = filter_url_create_root_path ({tpl1, tpl2 + ".html"});

// The flate engine crashes if the template does not exist, so be sure it exists.
if (!file_or_dir_exists (tpl)) {
Database_Logs::log ("Cannot find template file " + tpl);
return string();
return std::string();
}

// Instantiate and fill the template engine.
Flate flate;

// Copy the variables and zones and iterations to the engine.
map <string, string>::iterator iter1;
std::map <std::string, std::string>::iterator iter1 {};
for (iter1 = m_variables.begin (); iter1 != m_variables.end(); ++iter1) {
flate.set_variable (iter1->first, iter1->second);
}
map <string, bool>::iterator iter2;
std::map <std::string, bool>::iterator iter2{};
for (iter2 = m_zones.begin (); iter2 != m_zones.end(); ++iter2) {
flate.enable_zone (iter2->first);
}
flate.iterations = m_iterations;

// Get and return the page contents.
string page = flate.render (tpl);
return page;
return flate.render (tpl);
}
10 changes: 5 additions & 5 deletions assets/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Assets_View
{
public:
Assets_View ();
void set_variable (std::string key, std::string value);
void enable_zone (std::string zone);
void disable_zone (std::string zone);
void add_iteration (std::string key, std::map <std::string, std::string> value);
std::string render (std::string tpl1, std::string tpl2);
void set_variable (const std::string& key, const std::string& value);
void enable_zone (const std::string& zone);
void disable_zone (const std::string& zone);
void add_iteration (const std::string& key, const std::map <std::string, std::string>& value);
std::string render (const std::string& tpl1, const std::string& tpl2);
private:
std::map <std::string, std::string> m_variables {};
std::map <std::string, bool> m_zones {};
Expand Down
Loading

0 comments on commit 63234fc

Please sign in to comment.