Teuchos - Trilinos Tools Package  Version of the Day
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  const any &value_in, bool isDefault_in
79  )
80 {
81  val_ = value_in;
82  isDefault_ = isDefault_in;
83  validator_ = null;
84  isUsed_ = false;
85  docString_ = "";
86 }
87 
88 
90  RCP<const ParameterEntryValidator> const& validator_in
91  )
92 {
93  validator_ = validator_in;
94 }
95 
96 
97 void ParameterEntry::setDocString(const std::string &docString_in)
98 {
99  docString_ = docString_in;
100 }
101 
102 
104  bool isDefault_in, const std::string &docString_in
105  )
106 {
107  val_ = ParameterList();
108  isDefault_ = isDefault_in;
109  isUsed_ = true;
110  docString_ = docString_in;
111  return any_cast<ParameterList>( val_ );
112 }
113 
114 
116 {
117  return ( val_.empty() ? false : val_.type() == typeid(ParameterList) );
118 }
119 
120 std::ostream& ParameterEntry::leftshift(std::ostream& os, bool printFlags) const
121 {
122  if( !this->isList() ) os << val_;
123 
124  if(printFlags) {
125  if (isDefault_)
126  os << " [default]";
127  else if (!isUsed_)
128  os << " [unused]";
129  }
130 
131  return os;
132 }
133 
135  std::string formatString = getTwoDArrayTypeNameTraitsFormat();
136  size_t starPos = formatString.find("*");
137  std::string prefix = formatString.substr(0,starPos);
138  std::string postfix = formatString.substr(starPos+1);
139  std::string valueTypeName = val_.typeName();
140  size_t prePos = valueTypeName.find(prefix);
141  size_t postPos = valueTypeName.find(postfix);
142  return (prePos != std::string::npos) && (prePos==0)
143  && (postPos != std::string::npos) && (prePos < postPos);
144 }
145 
147  std::string formatString = getArrayTypeNameTraitsFormat();
148  size_t starPos = formatString.find("*");
149  std::string prefix = formatString.substr(0,starPos);
150  std::string postfix = formatString.substr(starPos+1);
151  std::string valueTypeName = val_.typeName();
152  size_t prePos = valueTypeName.find(prefix);
153  size_t postPos = valueTypeName.find(postfix);
154  return (prePos != std::string::npos) && (prePos==0)
155  && (postPos != std::string::npos) && (prePos < postPos);
156 }
157 
158 
159 // private
160 
161 
162 void ParameterEntry::reset()
163 {
164  //delete val_;
165  isUsed_ = false;
166  isDefault_ = false;
167 }
168 
169 
170 } // namespace Teuchos
171 
172 
Object held as the "value" in the Teuchos::ParameterList std::map.
Templated Parameter List class.
A thin wrapper around the Teuchos Array class that allows for 2 dimensional arrays.
This object is held as the "value" in the Teuchos::ParameterList std::map.
void setValidator(RCP< const ParameterEntryValidator > const &validator)
Set the validator.
ParameterList & setList(bool isDefault=false, const std::string &docString="")
Create a parameter entry that is an empty list.
ParameterEntry & operator=(const ParameterEntry &source)
Replace the current parameter entry with source.
ParameterEntry()
Default Constructor.
bool isTwoDArray() const
Test if the type of data being contained is a Teuchos::TwoDArray.
bool isArray() const
Test if the type of data being contained is a Teuchos::Array.
std::ostream & leftshift(std::ostream &os, bool printFlags=true) const
Output a non-list parameter to the given output stream.
void setDocString(const std::string &docString)
Set the documentation std::string.
bool isList() const
Return whether or not the value itself is a list.
void setAnyValue(const any &value, bool isDefault=false)
Set the value as an any object.
A list of parameters of arbitrary type.
Smart reference counting pointer class for automatic garbage collection.
Modified boost::any class, which is a container for a templated value.
const std::type_info & type() const
Return the type of value being stored.
std::string typeName() const
Return the name of the type.
bool empty() const
Return true if nothing is being stored.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...