| 108 | |
| 109 | |
| 110 | int |
| 111 | MultiSupportPattern::addMotion(GroundMotion &theMotion, int tag) |
| 112 | { |
| 113 | // ensure no motion with given tag already added |
| 114 | if (theMotionTags.getLocation(tag) >= 0) { |
| 115 | opserr << "MultiSupportPattern::addMotion - could not add new, motion with same tag exists\n"; |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | // make space for new |
| 120 | GroundMotion **newMotions = new GroundMotion *[numMotions+1]; |
| 121 | // GroundMotion **newMotions = (GroundMotion **)malloc(sizeof(GroundMotion *)*(numMotions+1)); |
| 122 | if (newMotions == 0) { |
| 123 | opserr << "MultiSupportPattern::addMotion - could not add new, out of mem\n"; |
| 124 | return -1; |
| 125 | } |
| 126 | |
| 127 | // copy old |
| 128 | for (int i=0; i<numMotions; i++) |
| 129 | newMotions[i] = theMotions[i]; |
| 130 | |
| 131 | // add the new motion to new |
| 132 | newMotions[numMotions] = &theMotion; |
| 133 | |
| 134 | // delete the old |
| 135 | if (theMotions != 0) |
| 136 | delete [] theMotions; |
| 137 | |
| 138 | // reset |
| 139 | theMotions = newMotions; |
| 140 | theMotionTags[numMotions] = tag; |
| 141 | numMotions++; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | |