xref: /AOO41X/main/configmgr/source/setnode.cxx (revision 3a7cf181c55416e69e525ddc0b38c22235ec1569) !
1*3a7cf181SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3a7cf181SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3a7cf181SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3a7cf181SAndrew Rist  * distributed with this work for additional information
6*3a7cf181SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3a7cf181SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3a7cf181SAndrew Rist  * "License"); you may not use this file except in compliance
9*3a7cf181SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*3a7cf181SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*3a7cf181SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3a7cf181SAndrew Rist  * software distributed under the License is distributed on an
15*3a7cf181SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3a7cf181SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3a7cf181SAndrew Rist  * specific language governing permissions and limitations
18*3a7cf181SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*3a7cf181SAndrew Rist  *************************************************************/
21*3a7cf181SAndrew Rist 
22*3a7cf181SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_configmgr.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <algorithm>
28cdf0e10cSrcweir #include <functional>
29cdf0e10cSrcweir #include <vector>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "rtl/ref.hxx"
32cdf0e10cSrcweir #include "rtl/ustring.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "data.hxx"
35cdf0e10cSrcweir #include "node.hxx"
36cdf0e10cSrcweir #include "nodemap.hxx"
37cdf0e10cSrcweir #include "setnode.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace configmgr {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // Work around some compilers' failure to accept
44cdf0e10cSrcweir // std::binder1st(std::ptr_fun(&Data::equalTemplateNames), ...):
45cdf0e10cSrcweir class EqualTemplateNames:
46cdf0e10cSrcweir     public std::unary_function< rtl::OUString const &, bool >
47cdf0e10cSrcweir {
48cdf0e10cSrcweir public:
EqualTemplateNames(rtl::OUString const & shortName)49cdf0e10cSrcweir     inline explicit EqualTemplateNames(rtl::OUString const & shortName):
50cdf0e10cSrcweir         shortName_(shortName) {}
51cdf0e10cSrcweir 
operator ()(rtl::OUString const & longName) const52cdf0e10cSrcweir     inline bool operator ()(rtl::OUString const & longName) const
53cdf0e10cSrcweir     { return Data::equalTemplateNames(shortName_, longName); }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir private:
56cdf0e10cSrcweir     rtl::OUString const & shortName_;
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
SetNode(int layer,rtl::OUString const & defaultTemplateName,rtl::OUString const & templateName)61cdf0e10cSrcweir SetNode::SetNode(
62cdf0e10cSrcweir     int layer, rtl::OUString const & defaultTemplateName,
63cdf0e10cSrcweir     rtl::OUString const & templateName):
64cdf0e10cSrcweir     Node(layer), defaultTemplateName_(defaultTemplateName),
65cdf0e10cSrcweir     templateName_(templateName), mandatory_(Data::NO_LAYER)
66cdf0e10cSrcweir {}
67cdf0e10cSrcweir 
clone(bool keepTemplateName) const68cdf0e10cSrcweir rtl::Reference< Node > SetNode::clone(bool keepTemplateName) const {
69cdf0e10cSrcweir     return new SetNode(*this, keepTemplateName);
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
getMembers()72cdf0e10cSrcweir NodeMap & SetNode::getMembers() {
73cdf0e10cSrcweir     return members_;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
getTemplateName() const76cdf0e10cSrcweir rtl::OUString SetNode::getTemplateName() const {
77cdf0e10cSrcweir     return templateName_;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
setMandatory(int layer)80cdf0e10cSrcweir void SetNode::setMandatory(int layer) {
81cdf0e10cSrcweir     mandatory_ = layer;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
getMandatory() const84cdf0e10cSrcweir int SetNode::getMandatory() const {
85cdf0e10cSrcweir     return mandatory_;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
getDefaultTemplateName() const88cdf0e10cSrcweir rtl::OUString const & SetNode::getDefaultTemplateName() const {
89cdf0e10cSrcweir     return defaultTemplateName_;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
getAdditionalTemplateNames()92cdf0e10cSrcweir std::vector< rtl::OUString > & SetNode::getAdditionalTemplateNames() {
93cdf0e10cSrcweir     return additionalTemplateNames_;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
isValidTemplate(rtl::OUString const & templateName) const96cdf0e10cSrcweir bool SetNode::isValidTemplate(rtl::OUString const & templateName) const {
97cdf0e10cSrcweir     return Data::equalTemplateNames(templateName, defaultTemplateName_) ||
98cdf0e10cSrcweir         (std::find_if(
99cdf0e10cSrcweir             additionalTemplateNames_.begin(),
100cdf0e10cSrcweir             additionalTemplateNames_.end(), EqualTemplateNames(templateName)) !=
101cdf0e10cSrcweir          additionalTemplateNames_.end());
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
SetNode(SetNode const & other,bool keepTemplateName)104cdf0e10cSrcweir SetNode::SetNode(SetNode const & other, bool keepTemplateName):
105cdf0e10cSrcweir     Node(other), defaultTemplateName_(other.defaultTemplateName_),
106cdf0e10cSrcweir     additionalTemplateNames_(other.additionalTemplateNames_),
107cdf0e10cSrcweir     mandatory_(other.mandatory_)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     cloneNodeMap(other.members_, &members_);
110cdf0e10cSrcweir     if (keepTemplateName) {
111cdf0e10cSrcweir         templateName_ = other.templateName_;
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
~SetNode()115cdf0e10cSrcweir SetNode::~SetNode() {}
116cdf0e10cSrcweir 
kind() const117cdf0e10cSrcweir Node::Kind SetNode::kind() const {
118cdf0e10cSrcweir     return KIND_SET;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
clear()121cdf0e10cSrcweir void SetNode::clear() {
122cdf0e10cSrcweir     members_.clear();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir }
126