mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-14 11:06:57 +01:00
added template class
This commit is contained in:
parent
a981fb3130
commit
19fe46d878
@ -337,6 +337,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\TabViewRenderer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\TemplateRenderer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\TextEditCellRenderer.h"
|
||||
>
|
||||
@ -485,6 +489,10 @@
|
||||
RelativePath=".\src\TabViewRenderer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\TemplateRenderer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\TextEditCellRenderer.cpp"
|
||||
>
|
||||
|
@ -332,6 +332,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\TabViewRenderer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\TemplateRenderer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\TextEditCellRenderer.h"
|
||||
>
|
||||
@ -476,6 +480,10 @@
|
||||
RelativePath=".\src\TabViewRenderer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\TemplateRenderer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\TextEditCellRenderer.cpp"
|
||||
>
|
||||
|
@ -0,0 +1,76 @@
|
||||
//
|
||||
// TemplateRenderer.h
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TemplateRenderer.h#1 $
|
||||
//
|
||||
// Library: ExtJS
|
||||
// Package: Core
|
||||
// Module: TemplateRenderer
|
||||
//
|
||||
// Definition of the TemplateRenderer class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ExtJS_TemplateRenderer_INCLUDED
|
||||
#define ExtJS_TemplateRenderer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/ExtJS/ExtJS.h"
|
||||
#include "Poco/WebWidgets/Renderer.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
class Frame;
|
||||
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
class ExtJS_API TemplateRenderer: public Poco::WebWidgets::Renderer
|
||||
/// TemplateRenderer renders a single Panel
|
||||
{
|
||||
public:
|
||||
TemplateRenderer();
|
||||
/// Creates the TemplateRenderer.
|
||||
|
||||
virtual ~TemplateRenderer();
|
||||
/// Destroys the TemplateRenderer.
|
||||
|
||||
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||
/// Emits code for the page header to the given output stream.
|
||||
|
||||
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||
/// Emits code for the page body to the given output stream.
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
||||
|
||||
#endif // ExtJS_TemplateRenderer_INCLUDED
|
70
WebWidgets/ExtJS/src/TemplateRenderer.cpp
Normal file
70
WebWidgets/ExtJS/src/TemplateRenderer.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// TemplateRenderer.cpp
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/ExtJS/src/TemplateRenderer.cpp#7 $
|
||||
//
|
||||
// Library: ExtJS
|
||||
// Package: Core
|
||||
// Module: TemplateRenderer
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/ExtJS/TemplateRenderer.h"
|
||||
#include "Poco/WebWidgets/Template.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
TemplateRenderer::TemplateRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TemplateRenderer::~TemplateRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TemplateRenderer::renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
poco_assert_dbg (pRenderable != 0);
|
||||
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::Template));
|
||||
const Template* pTemplate = static_cast<const Poco::WebWidgets::Template*>(pRenderable);
|
||||
pTemplate->parse(context, ostr);
|
||||
}
|
||||
|
||||
|
||||
void TemplateRenderer::renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
@ -277,6 +277,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\ResourceManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\Template.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\Type.h"
|
||||
>
|
||||
@ -357,6 +361,10 @@
|
||||
RelativePath=".\src\ResourceManager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Template.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Type.cpp"
|
||||
>
|
||||
|
@ -276,6 +276,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\ResourceManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\Template.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\Type.h"
|
||||
>
|
||||
@ -356,6 +360,10 @@
|
||||
RelativePath=".\src\ResourceManager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Template.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Type.cpp"
|
||||
>
|
||||
|
128
WebWidgets/include/Poco/WebWidgets/Template.h
Normal file
128
WebWidgets/include/Poco/WebWidgets/Template.h
Normal file
@ -0,0 +1,128 @@
|
||||
//
|
||||
// Template.h
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/Template.h#2 $
|
||||
//
|
||||
// Library: WebWidgets
|
||||
// Package: Templates
|
||||
// Module: Template
|
||||
//
|
||||
// Definition of the Template class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef WebWidgets_Template_INCLUDED
|
||||
#define WebWidgets_Template_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/Renderable.h"
|
||||
#include "Poco/FIFOEvent.h"
|
||||
#include "Poco/Any.h"
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
class RenderContext;
|
||||
|
||||
|
||||
class WebWidgets_API Template: public Renderable
|
||||
/// A JavaScript template class: Defines a template string which contains wildcards of the form %0, %1 %2 ...
|
||||
/// You can bind values to the wildcards. Values must be of type:
|
||||
/// - string, int, double, float, char, bool, Poco::WebWidgets::Renderable, DateTime
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<Template> Ptr;
|
||||
|
||||
Template(const std::string& templateStr);
|
||||
/// Creates a template string
|
||||
|
||||
Template(const std::string& templateStr, const std::vector<Poco::Any>& values);
|
||||
/// Creates a Template.
|
||||
|
||||
template<typename T>
|
||||
void setValue(std::size_t num, const T& val)
|
||||
/// Sets a value
|
||||
{
|
||||
bind(num, val);
|
||||
}
|
||||
|
||||
const std::string& templateStr() const;
|
||||
/// Returns the templatestr
|
||||
|
||||
std::size_t maxWildCard() const;
|
||||
/// Returns the largest wildcard
|
||||
|
||||
void parse(const RenderContext& ctx, std::ostream& out) const;
|
||||
/// The parse method will iterate over the template and write the expanded template to out
|
||||
|
||||
protected:
|
||||
Template(const std::string& templateStr, const std::type_info& type);
|
||||
/// Creates a Template.
|
||||
|
||||
~Template();
|
||||
/// Destroys the Template.
|
||||
|
||||
std::size_t detectMaxWildCard() const;
|
||||
|
||||
void bind(std::size_t num, int val);
|
||||
void bind(std::size_t num, float val);
|
||||
void bind(std::size_t num, double val);
|
||||
void bind(std::size_t num, char val);
|
||||
void bind(std::size_t num, bool val);
|
||||
void bind(std::size_t num, const std::string& val);
|
||||
void bind(std::size_t num, const char* pVal);
|
||||
void bind(std::size_t num, Renderable* pVal);
|
||||
void bind(std::size_t num, const Any& val);
|
||||
void write(const RenderContext& ctx, std::ostream& out, const Any& val) const;
|
||||
|
||||
private:
|
||||
std::string _templateStr;
|
||||
std::size_t _maxWildCard;
|
||||
std::vector<Poco::Any> _values;
|
||||
};
|
||||
|
||||
|
||||
inline const std::string& Template::templateStr() const
|
||||
{
|
||||
return _templateStr;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Template::maxWildCard() const
|
||||
{
|
||||
return _maxWildCard;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
#endif // WebWidgets_Template_INCLUDED
|
299
WebWidgets/src/Template.cpp
Normal file
299
WebWidgets/src/Template.cpp
Normal file
@ -0,0 +1,299 @@
|
||||
//
|
||||
// Template.cpp
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/src/Template.cpp#2 $
|
||||
//
|
||||
// Library: WebWidgets
|
||||
// Package: Templates
|
||||
// Module: Template
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/Template.h"
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
Template::Template(const std::string& templateStr):
|
||||
Renderable(typeid(Template)),
|
||||
_templateStr(templateStr),
|
||||
_maxWildCard(0),
|
||||
_values()
|
||||
{
|
||||
_maxWildCard = detectMaxWildCard();
|
||||
_values.resize(_maxWildCard);
|
||||
}
|
||||
|
||||
|
||||
Template::Template(const std::string& templateStr, const std::vector<Poco::Any>& values):
|
||||
Renderable(typeid(Template)),
|
||||
_templateStr(templateStr),
|
||||
_maxWildCard(values.size()),
|
||||
_values()
|
||||
{
|
||||
poco_assert (values.size() == detectMaxWildCard());
|
||||
_values.resize(_maxWildCard);
|
||||
|
||||
for (std::size_t i = 0; i < values.size(); ++i)
|
||||
bind(i, values[i]);
|
||||
}
|
||||
|
||||
|
||||
Template::Template(const std::string& templateStr, const std::type_info& type):
|
||||
Renderable(type),
|
||||
_templateStr(templateStr),
|
||||
_values()
|
||||
{
|
||||
_maxWildCard = detectMaxWildCard();
|
||||
_values.resize(_maxWildCard);
|
||||
}
|
||||
|
||||
|
||||
Template::~Template()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::size_t Template::detectMaxWildCard() const
|
||||
{
|
||||
// search for strings %num, take care of %%!
|
||||
bool inPercent = false;
|
||||
std::size_t maxVal(0);
|
||||
std::size_t curVal(0);
|
||||
std::size_t cnt(0);
|
||||
for (std::size_t i = 0; i < _templateStr.size(); ++i)
|
||||
{
|
||||
char c = _templateStr[i];
|
||||
if (inPercent)
|
||||
{
|
||||
if (c == '%')
|
||||
{
|
||||
if (cnt == 0) { // %%
|
||||
inPercent = false;
|
||||
curVal = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we read %123%
|
||||
if (curVal > maxVal)
|
||||
maxVal = curVal;
|
||||
// we remain within inPercent
|
||||
curVal = 0;
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
else if(isdigit(c))
|
||||
{
|
||||
curVal*=10;
|
||||
curVal += (c-'0');
|
||||
++cnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
inPercent = false;
|
||||
if (curVal > maxVal)
|
||||
maxVal = curVal;
|
||||
// we remain within inPercent
|
||||
curVal = 0;
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == '%')
|
||||
{
|
||||
inPercent = true;
|
||||
curVal = 0;
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return maxVal;
|
||||
}
|
||||
|
||||
|
||||
void Template::parse(const RenderContext& ctx, std::ostream& out) const
|
||||
{
|
||||
bool inPercent = false;
|
||||
std::size_t curVal(0);
|
||||
std::size_t cnt(0);
|
||||
|
||||
for (std::size_t i = 0; i < _templateStr.size(); ++i)
|
||||
{
|
||||
char c = _templateStr[i];
|
||||
if (inPercent)
|
||||
{
|
||||
if (c == '%')
|
||||
{
|
||||
if (cnt == 0) { // %%
|
||||
inPercent = false;
|
||||
curVal = 0;
|
||||
out << "%";
|
||||
}
|
||||
else
|
||||
{
|
||||
// we read %123%
|
||||
const Poco::Any& val = _values[curVal];
|
||||
write(ctx, out, val);
|
||||
// we remain within inPercent
|
||||
curVal = 0;
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
else if(isdigit(c))
|
||||
{
|
||||
curVal*=10;
|
||||
curVal += (c-'0');
|
||||
++cnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
inPercent = false;
|
||||
if (cnt > 0)
|
||||
write(ctx, out, _values[curVal]);
|
||||
else
|
||||
out << "%";
|
||||
curVal = 0;
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == '%')
|
||||
{
|
||||
inPercent = true;
|
||||
curVal = 0;
|
||||
cnt = 0;
|
||||
}
|
||||
else
|
||||
out.put(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, int val)
|
||||
{
|
||||
_values[num] = val;
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, float val)
|
||||
{
|
||||
_values[num] = val;
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, double val)
|
||||
{
|
||||
_values[num] = val;
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, char val)
|
||||
{
|
||||
_values[num] = val;
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, bool val)
|
||||
{
|
||||
_values[num] = val;
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, const std::string& val)
|
||||
{
|
||||
_values[num] = val;
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, const char* pVal)
|
||||
{
|
||||
std::string val(pVal);
|
||||
bind(num, val);
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, Renderable* pVal)
|
||||
{
|
||||
_values[num] = pVal;
|
||||
}
|
||||
|
||||
|
||||
void Template::bind(std::size_t num, const Any& val)
|
||||
{
|
||||
const std::type_info& type = val.type();
|
||||
Renderable* pRend = AnyCast<Renderable*>(val);
|
||||
if (pRend)
|
||||
bind(num, pRend);
|
||||
else if (type == typeid(std::string))
|
||||
bind(num, RefAnyCast<std::string>(val));
|
||||
else if (type == typeid(const char*))
|
||||
bind(num, RefAnyCast<const char*>(val));
|
||||
else if (type == typeid(int))
|
||||
bind(num, AnyCast<int>(val));
|
||||
else if (type == typeid(float))
|
||||
bind(num, AnyCast<float>(val));
|
||||
else if (type == typeid(double))
|
||||
bind(num, AnyCast<double>(val));
|
||||
else if (type == typeid(bool))
|
||||
bind(num, AnyCast<bool>(val));
|
||||
else /* if (type == typeid(char)) */
|
||||
bind(num, AnyCast<char>(val));
|
||||
}
|
||||
|
||||
|
||||
void Template::write(const RenderContext& ctx, std::ostream& out, const Any& val) const
|
||||
{
|
||||
if (val.empty())
|
||||
return;
|
||||
const std::type_info& type = val.type();
|
||||
Renderable* pRend = AnyCast<Renderable*>(val);
|
||||
if (pRend)
|
||||
pRend->renderHead(ctx, out);
|
||||
else if (type == typeid(std::string))
|
||||
out << RefAnyCast<std::string>(val);
|
||||
else if (type == typeid(int))
|
||||
out << AnyCast<int>(val);
|
||||
else if (type == typeid(float))
|
||||
out << AnyCast<float>(val);
|
||||
else if (type == typeid(double))
|
||||
out << AnyCast<double>(val);
|
||||
else if (type == typeid(bool))
|
||||
out << (AnyCast<bool>(val)?"true":"false");
|
||||
else /* if (type == typeid(char)) */
|
||||
out << AnyCast<char>(val);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
Loading…
Reference in New Issue
Block a user