Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ParameterEntry.cpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 
43 #include "Teuchos_ParameterEntry.hpp" // class definition
44 #include "Teuchos_ParameterList.hpp" // for sublists
45 #include "Teuchos_TwoDArray.hpp"
46 
47 
48 namespace Teuchos {
49 
50 
52  isUsed_(false),
53  isDefault_(false)
54 {}
55 
56 
58 {
59  operator=(source);
60 }
61 
62 
64 {
65  if (&source == this)
66  return *this;
67 
68  val_ = source.val_;
69  isUsed_ = source.isUsed_;
70  isDefault_ = source.isDefault_;
71  docString_ = source.docString_;
72  validator_ = source.validator_;
73 
74  return *this;
75 }
76 
78  : val_(std::move(other.val_)),
79  isUsed_(other.isUsed_),
80  isDefault_(other.isDefault_),
81  docString_(std::move(other.docString_)),
82  validator_(std::move(other.validator_))
83 {}
84 
86 {
87  if(this != &other)
88  {
89  this->val_ = std::move(other.val_);
90  this->isUsed_ = other.isUsed_;
91  this->isDefault_ = other.isDefault_;
92  this->docString_ = std::move(other.docString_);
93  this->validator_ = std::move(other.validator_);
94  }
95  return *this;
96 }
97 
99  const any &value_in, bool isDefault_in
100  )
101 {
102  val_ = value_in;
103  isDefault_ = isDefault_in;
104  validator_ = null;
105  isUsed_ = false;
106  docString_ = "";
107 }
108 
109 
111  RCP<const ParameterEntryValidator> const& validator_in
112  )
113 {
114  validator_ = validator_in;
115 }
116 
117 
118 void ParameterEntry::setDocString(const std::string &docString_in)
119 {
120  docString_ = docString_in;
121 }
122 
123 
125  bool isDefault_in, const std::string &docString_in
126  )
127 {
128  val_ = ParameterList();
129  isDefault_ = isDefault_in;
130  isUsed_ = true;
131  docString_ = docString_in;
132  return any_cast<ParameterList>( val_ );
133 }
134 
135 
137 {
138  return ( !val_.has_value() ? false : val_.type() == typeid(ParameterList) );
139 }
140 
141 std::ostream& ParameterEntry::leftshift(std::ostream& os, bool printFlags) const
142 {
143  if( !this->isList() ) os << val_;
144 
145  if(printFlags) {
146  if (isDefault_)
147  os << " [default]";
148  else if (!isUsed_)
149  os << " [unused]";
150  }
151 
152  return os;
153 }
154 
156  std::string formatString = getTwoDArrayTypeNameTraitsFormat();
157  size_t starPos = formatString.find("*");
158  std::string prefix = formatString.substr(0,starPos);
159  std::string postfix = formatString.substr(starPos+1);
160  std::string valueTypeName = val_.typeName();
161  size_t prePos = valueTypeName.find(prefix);
162  size_t postPos = valueTypeName.find(postfix);
163  return (prePos != std::string::npos) && (prePos==0)
164  && (postPos != std::string::npos) && (prePos < postPos);
165 }
166 
168  std::string formatString = getArrayTypeNameTraitsFormat();
169  size_t starPos = formatString.find("*");
170  std::string prefix = formatString.substr(0,starPos);
171  std::string postfix = formatString.substr(starPos+1);
172  std::string valueTypeName = val_.typeName();
173  size_t prePos = valueTypeName.find(prefix);
174  size_t postPos = valueTypeName.find(postfix);
175  return (prePos != std::string::npos) && (prePos==0)
176  && (postPos != std::string::npos) && (prePos < postPos);
177 }
178 
179 
180 // private
181 
182 
183 void ParameterEntry::reset()
184 {
185  //delete val_;
186  isUsed_ = false;
187  isDefault_ = false;
188 }
189 
190 
191 } // namespace Teuchos
192 
193 
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
Object held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
void setDocString(const std::string &docString)
Set the documentation std::string.
ParameterEntry()
Default Constructor.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
std::ostream & leftshift(std::ostream &os, bool printFlags=true) const
Output a non-list parameter to the given output stream.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
bool isArray() const
Test if the type of data being contained is a Teuchos::Array.
bool has_value() const
Checks whether the object contains a value.
void setAnyValue(const any &value, bool isDefault=false)
Set the value as an any object.
Modified boost::any class, which is a container for a templated value.
ParameterList & setList(bool isDefault=false, const std::string &docString="")
Create a parameter entry that is an empty list.
Templated Parameter List class.
bool isList() const
Return whether or not the value itself is a list.
A list of parameters of arbitrary type.
ParameterEntry & operator=(const ParameterEntry &source)
Replace the current parameter entry with source.
bool isTwoDArray() const
Test if the type of data being contained is a Teuchos::TwoDArray.
std::string typeName() const
Return the name of the type.
Smart reference counting pointer class for automatic garbage collection.
const std::type_info & type() const
Return the type of value being stored.