1
// Copyright (c) 2007, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
8
// * Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above
11
// copyright notice, this list of conditions and the following disclaimer
12
// in the documentation and/or other materials provided with the
14
// * Neither the name of Google Inc. nor the names of its
15
// contributors may be used to endorse or promote products derived from
16
// this software without specific prior written permission.
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
// Author: Jim Morrison
33
#include "config_for_unittests.h"
34
#include "tests/template_test_util.h"
35
#include <ctemplate/template_dictionary.h>
36
#include <ctemplate/template_namelist.h>
37
#include <ctemplate/template_string.h>
45
_START_GOOGLE_NAMESPACE_
47
TemporaryRegisterTemplate::TemporaryRegisterTemplate(const char* name) {
48
old_namelist_ = TemplateNamelist::namelist_;
50
namelist_ = *old_namelist_;
53
namelist_.insert(name);
54
TemplateNamelist::namelist_ = &namelist_;
57
TemporaryRegisterTemplate::~TemporaryRegisterTemplate() {
58
TemplateNamelist::namelist_ = old_namelist_;
61
const char* TemplateDictionaryPeer::GetSectionValue(
62
const TemplateString& variable)
64
return dict_->GetSectionValue(variable);
67
bool TemplateDictionaryPeer::IsHiddenSection(
68
const TemplateString& name) const {
69
return dict_->IsHiddenSection(name);
72
bool TemplateDictionaryPeer::IsUnhiddenSection(
73
const TemplateString& name) const {
74
return dict_->IsUnhiddenSection(name);
77
bool TemplateDictionaryPeer::IsHiddenTemplate(
78
const TemplateString& name) const {
79
return dict_->IsHiddenTemplate(name);
82
int TemplateDictionaryPeer::GetSectionDictionaries(
83
const TemplateString& section_name,
84
vector<const TemplateDictionary*>* dicts) const {
86
if (dict_->IsHiddenSection(section_name))
89
TemplateDictionaryInterface::Iterator* di =
90
dict_->CreateSectionIterator(section_name);
92
dicts->push_back(static_cast<const TemplateDictionary*>(&di->Next()));
95
return static_cast<int>(dicts->size());
98
int TemplateDictionaryPeer::GetIncludeDictionaries(
99
const TemplateString& section_name,
100
vector<const TemplateDictionary*>* dicts) const {
102
if (dict_->IsHiddenTemplate(section_name))
105
TemplateDictionaryInterface::Iterator* di =
106
dict_->CreateTemplateIterator(section_name);
107
while (di->HasNext())
108
dicts->push_back(static_cast<const TemplateDictionary*>(&di->Next()));
111
return static_cast<int>(dicts->size());
114
const char* TemplateDictionaryPeer::GetIncludeTemplateName(
115
const TemplateString& variable, int dictnum) const {
116
return dict_->GetIncludeTemplateName(variable, dictnum);
119
const char* TemplateDictionaryPeer::GetFilename() const {
120
return dict_->filename_;
123
_END_GOOGLE_NAMESPACE_