xref: /trunk/main/configmgr/source/setnode.cxx (revision cdf0e10c)
1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #include "precompiled_configmgr.hxx"
29 #include "sal/config.h"
30 
31 #include <algorithm>
32 #include <functional>
33 #include <vector>
34 
35 #include "rtl/ref.hxx"
36 #include "rtl/ustring.hxx"
37 
38 #include "data.hxx"
39 #include "node.hxx"
40 #include "nodemap.hxx"
41 #include "setnode.hxx"
42 
43 namespace configmgr {
44 
45 namespace {
46 
47 // Work around some compilers' failure to accept
48 // std::binder1st(std::ptr_fun(&Data::equalTemplateNames), ...):
49 class EqualTemplateNames:
50     public std::unary_function< rtl::OUString const &, bool >
51 {
52 public:
53     inline explicit EqualTemplateNames(rtl::OUString const & shortName):
54         shortName_(shortName) {}
55 
56     inline bool operator ()(rtl::OUString const & longName) const
57     { return Data::equalTemplateNames(shortName_, longName); }
58 
59 private:
60     rtl::OUString const & shortName_;
61 };
62 
63 }
64 
65 SetNode::SetNode(
66     int layer, rtl::OUString const & defaultTemplateName,
67     rtl::OUString const & templateName):
68     Node(layer), defaultTemplateName_(defaultTemplateName),
69     templateName_(templateName), mandatory_(Data::NO_LAYER)
70 {}
71 
72 rtl::Reference< Node > SetNode::clone(bool keepTemplateName) const {
73     return new SetNode(*this, keepTemplateName);
74 }
75 
76 NodeMap & SetNode::getMembers() {
77     return members_;
78 }
79 
80 rtl::OUString SetNode::getTemplateName() const {
81     return templateName_;
82 }
83 
84 void SetNode::setMandatory(int layer) {
85     mandatory_ = layer;
86 }
87 
88 int SetNode::getMandatory() const {
89     return mandatory_;
90 }
91 
92 rtl::OUString const & SetNode::getDefaultTemplateName() const {
93     return defaultTemplateName_;
94 }
95 
96 std::vector< rtl::OUString > & SetNode::getAdditionalTemplateNames() {
97     return additionalTemplateNames_;
98 }
99 
100 bool SetNode::isValidTemplate(rtl::OUString const & templateName) const {
101     return Data::equalTemplateNames(templateName, defaultTemplateName_) ||
102         (std::find_if(
103             additionalTemplateNames_.begin(),
104             additionalTemplateNames_.end(), EqualTemplateNames(templateName)) !=
105          additionalTemplateNames_.end());
106 }
107 
108 SetNode::SetNode(SetNode const & other, bool keepTemplateName):
109     Node(other), defaultTemplateName_(other.defaultTemplateName_),
110     additionalTemplateNames_(other.additionalTemplateNames_),
111     mandatory_(other.mandatory_)
112 {
113     cloneNodeMap(other.members_, &members_);
114     if (keepTemplateName) {
115         templateName_ = other.templateName_;
116     }
117 }
118 
119 SetNode::~SetNode() {}
120 
121 Node::Kind SetNode::kind() const {
122     return KIND_SET;
123 }
124 
125 void SetNode::clear() {
126     members_.clear();
127 }
128 
129 }
130