1 /* -------------------------------------------------------------------------- *
2 * OpenSim: PropertyObj.cpp *
3 * -------------------------------------------------------------------------- *
4 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. *
5 * See http://opensim.stanford.edu and the NOTICE file for more information. *
6 * OpenSim is developed at Stanford University and supported by the US *
7 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA *
8 * through the Warrior Web program. *
9 * *
10 * Copyright (c) 2005-2017 Stanford University and the Authors *
11 * Author(s): Frank C. Anderson *
12 * *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
14 * not use this file except in compliance with the License. You may obtain a *
15 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
16 * *
17 * Unless required by applicable law or agreed to in writing, software *
18 * distributed under the License is distributed on an "AS IS" BASIS, *
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
20 * See the License for the specific language governing permissions and *
21 * limitations under the License. *
22 * -------------------------------------------------------------------------- */
23
24 /* Note: This code was originally developed by Realistic Dynamics Inc.
25 * Author: Frank C. Anderson
26 */
27
28
29 //============================================================================
30 // INCLUDES
31 //============================================================================
32 #include "PropertyObj.h"
33
34
35
36
37 using namespace OpenSim;
38 using namespace std;
39
40
41 //=============================================================================
42 // CONSTRUCTOR(S)
43 //=============================================================================
44 //_____________________________________________________________________________
45 /**
46 * Destructor.
47 */
~PropertyObj()48 PropertyObj::~PropertyObj()
49 {
50 if(_value!=NULL) { delete _value; _value=NULL; }
51 }
52 //_____________________________________________________________________________
53 /**
54 * Constructor.
55 */
56 PropertyObj::
PropertyObj(const string & aName,const Object & aValue)57 PropertyObj(const string &aName,const Object &aValue) :
58 Property_Deprecated(Property_Deprecated::Obj,aName)
59 {
60 setName(aName);
61 _value = aValue.clone();
62 _value->setName(aName);
63 setAllowableListSize(1,1);
64 }
65 //_____________________________________________________________________________
66 /**
67 * Default Constructor.
68 */
69 PropertyObj::
PropertyObj()70 PropertyObj() :
71 Property_Deprecated(Property_Deprecated::Obj,"Object")
72 {
73 _value = 0;
74 setAllowableListSize(1,1);
75 }
76 //_____________________________________________________________________________
77 /**
78 * Copy constructor.
79 *
80 * @param aProperty Property_Deprecated to be copied.
81 */
PropertyObj(const PropertyObj & aProperty)82 PropertyObj::PropertyObj(const PropertyObj &aProperty) :
83 Property_Deprecated(aProperty)
84 {
85 _value = aProperty.getValueObj().clone();
86 }
87 //_____________________________________________________________________________
88 /**
89 * Construct and return a copy of this property.
90 * The property is allocated using the new operator, so the caller is
91 * responsible for deleting the returned object.
92 *
93 * @return Copy of this property.
94 */
clone() const95 PropertyObj* PropertyObj::clone() const
96 {
97 PropertyObj *property = new PropertyObj(*this);
98 return(property);
99 }
100
101
102 //=============================================================================
103 // OPERATORS
104 //=============================================================================
105 //-----------------------------------------------------------------------------
106 // ASSIGNMENT
107 //-----------------------------------------------------------------------------
108 //_____________________________________________________________________________
109 /**
110 * Assign this property to another.
111 *
112 * @param aProperty Property_Deprecated to which to assign this property.
113 * @return Reference to this property.
114 */
115 PropertyObj& PropertyObj::
operator =(const PropertyObj & aProperty)116 operator=(const PropertyObj &aProperty)
117 {
118 Property_Deprecated::operator =(aProperty);
119 if(_value!=NULL) { delete _value; _value=NULL; }
120 _value = aProperty.getValueObj().clone();
121 return(*this);
122 }
123
assign(const AbstractProperty & that)124 void PropertyObj::assign(const AbstractProperty& that) {
125 try {
126 *this = dynamic_cast<const PropertyObj&>(that);
127 } catch(const std::bad_cast&) {
128 OPENSIM_THROW(InvalidArgument,
129 "Unsupported type. Expected: " + this->getTypeName() +
130 " | Received: " + that.getTypeName());
131 }
132 }
133
134 //=============================================================================
135 // GET AND SET
136 //=============================================================================
137
138 //-----------------------------------------------------------------------------
139 // VALUE
140 //-----------------------------------------------------------------------------
141 //_____________________________________________________________________________
142 /**
143 * Get a reference to the value of this property. Note that the returned
144 * reference can be used to change the value of this property.
145 *
146 * @return Reference to the value of this property.
147 */
148 Object& PropertyObj::
getValueObj()149 getValueObj()
150 {
151 return((*_value));
152 }
153 //_____________________________________________________________________________
154 /**
155 * Get a constant reference to the value of this property.
156 *
157 * @return Constant reference to the value of this property.
158 */
159 const Object& PropertyObj::
getValueObj() const160 getValueObj() const
161 {
162 return((*_value));
163 }
164 //_____________________________________________________________________________
165 /**
166 * Get a constant String representing the value of this property.
167 *
168 * @return Constant String representing the value of this property.
169 */
170 string PropertyObj::
toString() const171 toString() const
172 {
173 return "(Object)";
174 }
175