PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PEBLObject.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/base/PEBLObjectBase.cpp
4// Purpose: Contains a simple list class, part of the Variant Class
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#include "PEBLObject.h"
28
29#include "../base/PComplexData.h"
30#include "../utility/PError.h"
31#include "../utility/PEBLUtility.h"
32#include <stdio.h>
33
34using std::cout;
35using std::cerr;
36using std::endl;
37using std::flush;
38using std::list;
39using std::ostream;
40
41
53
58
61{
62 mProperties.clear();
63 // cout << "Deleting pob\n";
64}
65
66
67bool PEBLObjectBase::SetProperty(std::string name, Variant v)
68{
69
71
72 if(err == OVE_SUCCESS)
73 {
74 mProperties[name]=v;
75 return true;
76 }
77 else
78 {
79 Variant msg = Variant("Failing to set property:[") +
80 Variant(name)+ Variant("]:[")+v+Variant("]\n");
81
83 return false;
84 }
85}
86
87
89{
90 mProperties[name]=v;
91 return true;
92}
93
94Variant PEBLObjectBase::GetProperty(const std::string name)const
95{
96
97 std::string uname = PEBLUtility::ToUpper(name);
98
99
101
102
103
104 if((err == OVE_SUCCESS ) | ( err == OVE_VALID ))
105 {
106 return mProperties.find(uname)->second;
107 }
108 else
109 {
110 PError::SignalFatalError("Attempted to get invalid property [" + name + "] of object.");
111 }
112 return Variant(0);
113}
114
115
116//By default, just check to see if the property exists.
118{
119
120 return ValidateProperty(name);
121}
122
124{
125
126 std::string uname = PEBLUtility::ToUpper(name);
127
128
129#if 0
130 cout << "Testing: [" << uname << "]" <<endl;
131 cout << "Object is: " << *this << endl;
132 cout << "-----------------\n";
133
134 std::map<std::string, Variant>::const_iterator i;
135 i = mProperties.begin();
136 while(i != mProperties.end())
137 {
138 cout << "[" << i->first << "]: " << i->second << endl;
139 i++;
140 }
141 cout << "----------\n";
142#endif
143
144
145 if(mProperties.find(uname) == mProperties.end())
146 {
147
149 }
150 else
151 {
152
153 return OVE_SUCCESS;
154 }
155}
156
157
158//Overload of the << operator
159std::ostream & operator <<(std::ostream & out, const PEBLObjectBase & object )
160{
161 object.SendToStream(out);
162 return out;
163}
164
165
166
167std::string PEBLObjectBase::ObjectName() const
168{
169 return "<Unknown PEBLObjectBase>";
170}
171
172ostream & PEBLObjectBase::PrintProperties(ostream& out)
173{
174 out << "----------\n";
175 std::map<std::string, Variant>::const_iterator i;
176 i = mProperties.begin();
177 while(i != mProperties.end())
178 {
179 out << "[" << i->first << "]: " << i->second << endl;
180 i++;
181 }
182 out << "----------\n";
183
184
185 return out;
186
187}
188
189
191{
192
193 //Create a plist to put the properties in
194
195 PList * newlist = new PList();
196
197
198
199 std::map<std::string, Variant>::const_iterator i;
200 i = mProperties.begin();
201 while(i != mProperties.end())
202 {
203 newlist->PushBack(i->first);
204 i++;
205 }
206
208 tmpObj = counted_ptr<PEBLObjectBase>(newlist);
209 PComplexData * tmpPCD = (new PComplexData(tmpObj));
210 Variant tmp = Variant(tmpPCD);
211 delete tmpPCD;
212 tmpPCD=NULL;
213 return tmp;
214
215}
216
217
218
219// Inheritable function that is called by friend method << operator of PComplexData
220ostream & PEBLObjectBase::SendToStream(ostream& out) const
221{
222 out << ObjectName() << flush;
223 return out;
224}
#define NULL
Definition BinReloc.cpp:317
std::ostream & operator<<(std::ostream &out, const PEBLObjectBase &object)
ObjectValidationError
Definition PEBLObject.h:37
@ OVE_SUCCESS
Definition PEBLObject.h:38
@ OVE_INVALID_PROPERTY_NAME
Definition PEBLObject.h:40
@ OVE_VALID
Definition PEBLObject.h:39
ComplexDataType
Definition PEBLObject.h:45
@ CDT_UNDEFINED
Definition PEBLObject.h:46
virtual std::string ObjectName() const
virtual std::ostream & SendToStream(std::ostream &out) const
virtual bool InitializeProperty(std::string name, Variant v)
virtual ~PEBLObjectBase()
Standard Destructor.
virtual bool SetProperty(std::string name, Variant v)
std::map< std::string, Variant > mProperties
Definition PEBLObject.h:112
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
virtual std::ostream & PrintProperties(std::ostream &out)
ComplexDataType mCDT
Definition PEBLObject.h:109
Variant GetProperty(std::string) const
virtual Variant GetPropertyList()
PEBLObjectBase()
Standard Constructor.
Definition PList.h:45
void PushBack(const Variant &v)
Definition PList.cpp:149
std::string ToUpper(const std::string &text)
void SignalFatalError(const std::string &message)