Main  /  Edit  /  History  /   /  Users Area

cppcms::base_view & cppcms::base_content

cppcms::base_content

This is simple polymorphic class that every content for cppcms template system should be derided. It allows dynamic casting of the content to correct one for target application:

class base_content {
public:
    virtual ~base_content() {};
};

cppcms::base_view

Members

How Derived Classes are created:

This is the class that every view generated from the template system is derived from.

Every derived class defines important public member — content — the reference to user defined content class.

It also creates member functions for each implemented template. For example:

<% c++ #include "data.h" %>
<% namespace my_view %>
<% class message uses data::message %>
<% template render() %>
<html>
  <body>
    <h1><% message %> World!</h1>
  </body>
<html>
<% end template %>
<% end class %>
<% end namespace %>

Is rendered to C++ output:

#include "data.h"
namespace my_view {
    struct message :public cppcms::base_view
    {
        data::message &content;
        cppcms::transtext::trans const *tr;
        message(cppcms::base_view::settings _s,data::message &_content):
            cppcms::base_view(_s),content(_content)
        {
            tr=_s.worker->domain_gettext("my_view");
        };
        virtual void render() {
            cout<<"\n"
                "<html>\n"
                "  <body>\n"
                "    <h1>";
            cout<<escape(content.message);
            cout<<" World!</h1>\n"
                "  </body>\n"
                "<html>\n"
                "";
        } // end of template render
    }; // end of class message
} // end of namespace my_view

Member functions

Default filter

template<typename T>
string escape(T const &v)

This is default filter, performs rendering of input parameter to text. This function is always called when template parameter is substituted without filters, i.e.:

<% param %>

is converted to

cout<<escape(content.param);

By default, it uses ostream to render the output, however it provides several specializations:

Provided Filters

They are called when some filters are given. Each filter has following possible signatures:

string filter_name(Type const &inp);
string filter_name(Type const &inp,string param);

Where inp is given filter input and param is filter parameter.

Other member functions

boost::format format(string const &f);

Function that returns boost::format object constructed with f and with disabled exceptions. In generally boost::format throw exception in case of incorrect format or parameters list — this is not such a good behavior for displaying various data.

It is used mostly by gettext and ngettext implementations. For example

<% ngt "We have one apple","We have %1% apples",n using n %>

Is rendered to:

cout<<format(tr->gettext("We have one apple","We have %1% apples",n)) % escape(n);

Thus it would not throw in case of "one apple".

About

Wiki++ is a wiki engine powered by CppCMS web development framework.

Mirrors

Hosted By

SourceForge.net Logo


Navigation

Main Page



Valid CSS | Valid XHTML 1.0