DCL 4.0
Loading...
Searching...
No Matches
TextTemplate Class Reference

#include <TextTemplate.h>

Inheritance diagram for TextTemplate:
Object

Protected Member Functions

virtual String onSQLFieldValue (_CONST SQLField &_field, const String &_fieldIsNullValue)
void parseHelper (const char_t *_begin, const char_t *_end)
void parse (const char_t *_begin, const char_t *_end)
int append (const char_t *_name, const String &_value, bool _clearExists)
int append (const char_t *_name, const TextTemplate &_template, bool _clearExists)
int append (const StringStringArray &_nameToValues, bool _clearExists)
int append (_CONST SQLFields &_fields, const String &_fieldIsNullValue, bool _clearExists)
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Protected Attributes

void * __textList
void * __subTemplateMap

Additional Inherited Members

Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Detailed Description

Definition at line 21 of file TextTemplate.h.

Member Function Documentation

◆ append() [1/4]

int TextTemplate::append ( _CONST SQLFields & _fields,
const String & _fieldIsNullValue,
bool _clearExists )
protected

Definition at line 272 of file TextTemplate.cpp.

274{
275 int nCount = 0;
276 for(size_t i = 0; i < _fields.count(); i++)
277 {
278 _CONST SQLField& field = _fields[i];
279 nCount += append(
280 field.name(),
281 onSQLFieldValue(field, _fieldIsNullValue),
282 _clearExists
283 );
284 }
285 return nCount;
286}
#define _CONST
Definition Config.h:353
virtual String onSQLFieldValue(_CONST SQLField &_field, const String &_fieldIsNullValue)

◆ append() [2/4]

int TextTemplate::append ( const char_t * _name,
const String & _value,
bool _clearExists )
protected

Definition at line 182 of file TextTemplate.cpp.

184{
185 int nCount = 0;
186 TextList::Iterator it = TEXT_LIST()->begin();
187 if (_name != NULL)
188 {
189 for(; it != TEXT_LIST()->end(); it++)
190 {
191 if ((*it).name == _name)
192 {
193 if (_clearExists && !(*it).values.isEmpty())
194 (*it).values.clear();
195
196 (*it).values.addTail(_value);
197 nCount++;
198 }
199 }
200 }
201 else
202 {
203 for(; it != TEXT_LIST()->end(); it++)
204 {
205 if (!(*it).name.isEmpty())
206 {
207 if (_clearExists && !(*it).values.isEmpty())
208 (*it).values.clear();
209
210 (*it).values.addTail(_value);
211 nCount++;
212 }
213 }
214 }
215 return nCount;
216}
#define NULL
Definition Config.h:340
#define TEXT_LIST()

◆ append() [3/4]

int TextTemplate::append ( const char_t * _name,
const TextTemplate & _template,
bool _clearExists )
protected

Definition at line 218 of file TextTemplate.cpp.

220{
221 __DCL_ASSERT(_name != NULL);
222 __DCL_ASSERT(&_template != this);
223
224 int nCount = 0;
225 TextList::Iterator it = TEXT_LIST()->begin();
226 for(; it != TEXT_LIST()->end(); it++)
227 {
228 if ((*it).name == _name)
229 {
230 if (_clearExists && !(*it).values.isEmpty())
231 (*it).values.clear();
232
233 TextList::ConstIterator itSrc =
234 ((const TextList*)_template.__textList)->begin();
235 for(; itSrc != ((const TextList*)_template.__textList)->end(); itSrc++)
236 {
237 if (!(*itSrc).values.isEmpty())
238 {
239 (*it).values.insert(
240 (*it).values.end(),
241 (*itSrc).values.begin(),
242 (*itSrc).values.end()
243 );
244 }
245#ifdef __DCL_DEBUG
246 else
247 {
248 __DCL_ASSERT(!((*itSrc).name.isEmpty()));
249 if (_template.__showEmptyName)
250 {
251 String name = L'$' + (*itSrc).name;
252 (*it).values.addTail(name);
253 }
254 }
255#endif
256 }
257 nCount++;
258 }
259 }
260 return nCount;
261}
#define __DCL_ASSERT(expr)
Definition Object.h:371
List< TextNode > TextList
void * __textList

◆ append() [4/4]

int TextTemplate::append ( const StringStringArray & _nameToValues,
bool _clearExists )
protected

Definition at line 263 of file TextTemplate.cpp.

265{
266 int nCount = 0;
267 for(size_t i = 0; i < _nameToValues.size(); i++)
268 nCount += append(_nameToValues[i].key, _nameToValues[i].value, _clearExists);
269 return nCount;
270}

◆ onSQLFieldValue()

String TextTemplate::onSQLFieldValue ( _CONST SQLField & _field,
const String & _fieldIsNullValue )
protectedvirtual

Definition at line 288 of file TextTemplate.cpp.

290{
291 if (_field.isNull() || _field.dataSize() == 0)
292 return _fieldIsNullValue;
293
294 return _field.asString();
295}

◆ parse()

void TextTemplate::parse ( const char_t * _begin,
const char_t * _end )
protected

Definition at line 426 of file TextTemplate.cpp.

427{
428 try
429 {
430 Regex reBegin(
431 __T("<!--[\t\v\f ]*\\$[a-zA-Z0-9_]+[\t\v\f ]*-->[\t\v\f \r\n]*")
432 );
433
434 Regex::MatchResults matchBegin;
435 while (_begin < _end && reBegin.search(_begin, _end, matchBegin)) {
436 __DCL_ASSERT(matchBegin.size() > 0 && matchBegin[0].matched);
437
438 // sub 템플릿의 시작을 찾았다.
439 String _name = __getName(matchBegin[0].first, matchBegin[0].second);
440 String strEndPattern =
441 __T("<!--[\t\v\f ]*/[\t\v\f ]*\\$")
442 + _name
443 + __T("[\t\v\f ]*-->[\t\v\f \r\n]*");
444
445 Regex reEnd(strEndPattern);
446 Regex::MatchResults matchEnd;
447// __DCL_TRACE1(L"%lc\n", *(psz + matchBegin.rm_eo));
448 if (reEnd.search(matchBegin[0].second, _end, matchEnd)) {
449 // sub 블록 이전에 대하여 템플릿을 구성한다.
450 if (_begin < matchBegin[0].first) {
451 parseHelper(_begin, matchBegin[0].first);
452 }
453
454 // _name 템플릿을 구성한다.
455 // sub 템플릿에 같은 이름을 사용하는 템플릿이 있으면
456 // 기존의 템플릿의 내용을 삭제한다.
457#ifdef __DCL_DEBUG
458 SubTemplateMap::Iterator itMap = SUB_TEMPLATE_MAP()->find(_name);
459 if (itMap != SUB_TEMPLATE_MAP()->end()) {
461 __T("Warning - exists %ls ==> replaced\n"),
462 _name.data()
463 );
464 }
465#endif
466 SUB_TEMPLATE_MAP()->erase(_name);
467
468 TextNode node;
469 node.name = _name;
470 TEXT_LIST()->addTail(node);
471
472 TextTemplate& sub = (*SUB_TEMPLATE_MAP())[_name];
473// __DCL_TRACE2("%ls: %d\n", _name.data(), matchEnd.rm_so);
474 if (matchBegin[0].second < matchEnd[0].first) {
475 sub.parse(matchBegin[0].second, matchEnd[0].first);
476 }
477
478 _begin = matchEnd[0].second;
479// __DCL_TRACE1(L"%ls\n", psz);
480 }
481 else {
482 _begin = matchBegin[0].second;
483 }
484 }
485
486 if (_begin < _end) {
487 // 남은 데이터가 있다
488 parseHelper(_begin, _end);
489 }
490 }
491 catch(RegexException* e) {
492 __DCL_TRACE1(__T("%ls\n"), e->toString().data());
493 e->destroy();
494 __DCL_ASSERT(false);
495 }
496}
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:376
#define __T(str)
Definition Object.h:44
#define SUB_TEMPLATE_MAP()
virtual void destroy()
Definition Exception.cpp:74
size_t size() const
Definition Regex.h:57
void parseHelper(const char_t *_begin, const char_t *_end)
String name

◆ parseHelper()

void TextTemplate::parseHelper ( const char_t * _begin,
const char_t * _end )
protected

Definition at line 372 of file TextTemplate.cpp.

373{
374 try {
375 Regex re(__T("\\$[a-zA-Z0-9_]+"));
376 Regex::MatchResults results;
377 while(_begin < _end && re.search(_begin, _end, results)) {
378 if (results[0].matched && results[0].first < results[0].second) {
379 // $NAME 이전에 텍스트가 있다.
380 if (_begin < results[0].first) {
381 String text(_begin, results[0].first);
382 TextNode node;
383 node.values.addTail(text);
384 TEXT_LIST()->addTail(node);
385 }
386
387 // '$' 는 제외한다.
388 String name(results[0].first + 1, results[0].second);
389 TextNode node;
390 node.name = name;
391 TEXT_LIST()->addTail(node);
392
393 _begin = results[0].second;
394 }
395 }
396
397 if (_begin < _end) {
398 // $NAME 이후에 텍스트가 있다.
399 String text(_begin, _end);
400 TextNode node;
401 node.values.addTail(text);
402 TEXT_LIST()->addTail(node);
403 }
404 }
405 catch(RegexException* e) {
406 __DCL_TRACE1(__T("%ls\n"), e->toString().data());
407 e->destroy();
408 __DCL_ASSERT(false);
409 }
410}
StringList values

Member Data Documentation

◆ __subTemplateMap

void* TextTemplate::__subTemplateMap
protected

Definition at line 74 of file TextTemplate.h.

◆ __textList

void* TextTemplate::__textList
protected

Definition at line 73 of file TextTemplate.h.


The documentation for this class was generated from the following files: