PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PCustomObject.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/objects/PCustomObject.cpp
4// Purpose: Contains generic specs for all objects containing text
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2013-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 "../utility/PError.h"
28#include "PCustomObject.h"
29#include "../base/PList.h"
30#include "../base/PComplexData.h"
31#include "../base/Variant.h"
32#include <string>
33#include <iostream>
34using std::cout;
35using std::endl;
36
39 mName("Unknown Custom Object")
40{
41
42
43}
44
45
46
47PCustomObject::PCustomObject(const std::string & name):
49 mName(name)
50{
51
52}
53
54
56 PEBLObjectBase(object)
57
58{
59
60}
61
62
67
68
69bool PCustomObject::SetProperty(std::string name, Variant v)
70{
71 //We won't do any validation here. Maybe in the future
72 //some validation could be done here; allowing the usere
73 //to specify things like value type, or a subset of values.
74 std::string uname = PEBLUtility::ToUpper(name);
75 bool newname = (mProperties.find(uname) == mProperties.end());
76
77 mProperties[uname]=v;
78
79 if(newname){
80 mObjectOrder.push_back(std::string(name));
81 }
82
83 return true;
84}
85
86
87Variant PCustomObject::GetProperty(std::string name)const
88{
89 std::string uname = PEBLUtility::ToUpper(name);
90 return PEBLObjectBase::GetProperty(uname);
91}
92
93
95{
96 return ValidateProperty(name);
97}
98
100{
102 if(ove == OVE_VALID)
103 return ove;
104 else
106
107}
108
109
111std::ostream & PCustomObject::SendToStream(std::ostream& out) const
112{
113 out << ObjectName()<< std::flush;
114 return out;
115}
116
117
118std::string PCustomObject::ObjectName() const
119{
120 return mName;
121}
122
123
124std::ostream & PCustomObject::PrintProperties(std::ostream& out)
125{
126 out << "----------\n";
127 for(std::list<std::string>::iterator i = mObjectOrder.begin(); i != mObjectOrder.end(); ++i)
128 {
129 std::string name = (*i);
130 std::string uname = PEBLUtility::ToUpper(name);
131
132 out << "[" << name << "]: " << GetProperty(uname) << endl;
133
134 }
135 out << "----------\n";
136
137
138 return out;
139
140}
141
142
143
144
146{
147
148 PList * returnList = new PList();
149
150 for(std::list<std::string>::iterator i = mObjectOrder.begin(); i != mObjectOrder.end(); ++i)
151 {
152 returnList->PushBack(Variant(*i));
153 }
154
156 PComplexData * tmpPCD= (new PComplexData(tmpObj));
157 Variant tmp = Variant(tmpPCD);
158 delete tmpPCD;
159 tmpPCD=NULL;
160 return tmp;
161}
#define NULL
Definition BinReloc.cpp:317
ObjectValidationError
Definition PEBLObject.h:37
@ OVE_INVALID_PROPERTY_NAME
Definition PEBLObject.h:40
@ OVE_VALID
Definition PEBLObject.h:39
@ CDT_CUSTOMOBJECT
Definition PEBLObject.h:62
This class simply represent an abstract text-based object.
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
virtual Variant GetProperty(std::string) const
virtual bool SetProperty(std::string, Variant v)
virtual std::string ObjectName() const
std::string mName
virtual std::ostream & SendToStream(std::ostream &out) const
This sends the color descriptions to the specified stream.
virtual std::ostream & PrintProperties(std::ostream &out)
virtual ~PCustomObject()
std::list< std::string > mObjectOrder
virtual Variant GetPropertyList()
std::map< std::string, Variant > mProperties
Definition PEBLObject.h:112
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Variant GetProperty(std::string) const
Definition PList.h:45
void PushBack(const Variant &v)
Definition PList.cpp:149
std::string ToUpper(const std::string &text)