00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <classTags.h>
00026 #include <Parameter.h>
00027 #include <DomainComponent.h>
00028
00029 Parameter::Parameter(int passedTag,
00030 DomainComponent *parentObject,
00031 const char **argv, int argc)
00032 :TaggedObject(passedTag),
00033 theObjects(0), parameterID(0),
00034 numObjects(0), maxNumObjects(0)
00035 {
00036 int ok = -1;
00037
00038 maxNumObjects = initialSize;
00039
00040 theObjects = new MovableObject *[maxNumObjects];
00041 parameterID = new int[maxNumObjects];
00042
00043 if (parentObject != 0)
00044 ok = parentObject->setParameter(argv, argc, *this);
00045
00046 if (ok < 0)
00047 opserr << "Parameter::Parameter "<< this->getTag() <<" -- unable to set parameter" << endln;
00048 }
00049
00050 Parameter::Parameter(const Parameter ¶m):
00051 TaggedObject(param.getTag())
00052 {
00053 theInfo = param.theInfo;
00054 numObjects = param.numObjects;
00055 maxNumObjects = param.maxNumObjects;
00056
00057 theObjects = new MovableObject *[maxNumObjects];
00058 parameterID = new int[maxNumObjects];
00059
00060 for (int i = 0; i < numObjects; i++) {
00061 theObjects[i] = param.theObjects[i];
00062 parameterID[i] = param.parameterID[i];
00063 }
00064 }
00065
00066 Parameter::~Parameter()
00067 {
00068 if (theObjects != 0)
00069 delete [] theObjects;
00070
00071 if (parameterID != 0)
00072 delete [] parameterID;
00073 }
00074
00075 int
00076 Parameter::addObject(DomainComponent *parentObject,
00077 const char **argv, int argc)
00078 {
00079 return (parentObject != 0) ?
00080 parentObject->setParameter(argv, argc, *this) : -1;
00081 }
00082
00083 int
00084 Parameter::update(int newValue)
00085 {
00086 theInfo.theInt = newValue;
00087
00088 int ok = 0;
00089
00090 for (int i = 0; i < numObjects; i++)
00091 ok += theObjects[i]->updateParameter(parameterID[i], theInfo);
00092
00093 return ok;
00094 }
00095
00096 int
00097 Parameter::update(double newValue)
00098 {
00099 theInfo.theDouble = newValue;
00100
00101 int ok = 0;
00102
00103 for (int i = 0; i < numObjects; i++)
00104 ok += theObjects[i]->updateParameter(parameterID[i], theInfo);
00105
00106 return ok;
00107 }
00108
00109 int
00110 Parameter::activate(bool active)
00111 {
00112 int ok = 0;
00113 for (int i = 0; i < numObjects; i++) {
00114 ok += theObjects[i]->activateParameter(active ? parameterID[i] : 0);
00115 }
00116
00117 return ok;
00118 }
00119
00120 void
00121 Parameter::Print(OPS_Stream &s, int flag)
00122 {
00123 s << "Parameter, tag = " << this->getTag() << endln;
00124
00125 }
00126
00127 int
00128 Parameter::addObject(int paramID, MovableObject *object)
00129 {
00130
00131
00132 if (numObjects == maxNumObjects) {
00133 maxNumObjects += expandSize;
00134 MovableObject **newObjects = new MovableObject*[maxNumObjects];
00135 int *newParameterID = new int[maxNumObjects];
00136
00137 for (int i = 0; i < numObjects; i++) {
00138 newObjects[i] = theObjects[i];
00139 newParameterID[i] = parameterID[i];
00140 }
00141
00142 delete [] theObjects;
00143 delete [] parameterID;
00144
00145 theObjects = newObjects;
00146 parameterID = newParameterID;
00147 }
00148
00149 parameterID[numObjects] = paramID;
00150 theObjects[numObjects] = object;
00151 numObjects++;
00152
00153 return 0;
00154 }