Main  /  Edit  /  History  /   /  Users Area

cppcms::base_view & cppcms::base_content

<a name="cppcms::base_content"></a>

cppcms::base_content

This is a simple polymorphic class from which every cppcms content template should be derided. It allows dynamic casting of the content for the target application:

class base_content {
public:
    virtual ~base_content() {};
};
<a name="cppcms::base_view"></a>

cppcms::base_view

Members

<a name="How-Derived-Classes-are-created:"></a>

How Derived Classes are created:

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

Every derived class defines the important public member --- content --- the reference to the 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 %>

The above template 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 the default filter. It performs the rendering of the input parameter to text. This function is always called when the 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 the following possible signatures:

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

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

Other member functions

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

Function that returns i\a boost::format object constructed with f and with disabled exceptions. In generally boost::format throws an exception in case of an 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 an exception in case of "one apple".

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page



Valid CSS | Valid XHTML 1.0