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