本文整理汇总了C++中DynamicArray::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicArray::push_back方法的具体用法?C++ DynamicArray::push_back怎么用?C++ DynamicArray::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicArray
的用法示例。
在下文中一共展示了DynamicArray::push_back方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateJointOrdering
/**
HACK!
*/
void Character::updateJointOrdering(){
if( jointOrder.size() == joints.size() )
return; // HACK assume ordering is ok
jointOrder.clear();
if (!root)
return;
DynamicArray<ArticulatedRigidBody*> bodies;
bodies.push_back(root);
int currentBody = 0;
while ((uint)currentBody<bodies.size()){
//add all the children joints to the list
for (int i=0;i<bodies[currentBody]->getChildJointCount();i++){
Joint *j = bodies[currentBody]->getChildJoint(i);
jointOrder.push_back( getJointIndex(j->getName()) );
bodies.push_back(bodies[currentBody]->getChildJoint(i)->getChild());
}
currentBody++;
}
reverseJointOrder.resize( jointOrder.size() );
for( uint i=0; i < jointOrder.size(); ++i )
reverseJointOrder[jointOrder[i]] = i;
}
示例2:
void CartWheel3D::runStep(double dt) {
_nTime += dt;
DynamicArray<ContactPoint>* contactPoints = _world->getContactForces();
DynamicArray<Vector3d> humanPositions;
for (HumanItr itr = _humans.begin(); itr != _humans.end(); itr++) {
Human* human = (*itr).second;
SimBiController* c = human->getController();
if (NULL != c) {
c->performPreTasks(dt, contactPoints);
// Save the current position
humanPositions.push_back(human->getPosition());
BehaviourController* b = human->getBehaviour();
if (NULL != b) {
if (b->shouldAbort()) {
}
}
}
}
_world->advanceInTime(dt);
bool isHumansWorking = false;
bool isObjsWorking = false;
contactPoints = _world->getContactForces();
for (HumanItr itr = _humans.begin(); itr != _humans.end(); itr++) {
Human* human = (*itr).second;
SimBiController* c = human->getController();
if (NULL != c) {
c->performPostTasks(dt, contactPoints);
// Save the current position
humanPositions.push_back(human->getPosition());
BehaviourController* b = human->getBehaviour();
if (NULL != b) {
if (b->shouldAbort()) {
}
}
}
if(_behaviorsManager->runStep(human->getName().c_str(), _nTime)) {
// printf("nTime: %f\n", _nTime);
isHumansWorking = true;
}
}
for(int i=0; i<_objects.size(); i++) {
if(_behaviorsManager->runStep(_objects[i].c_str(), _nTime)) {
isObjsWorking = true;
}
}
if(!isHumansWorking && !isObjsWorking) {
_behaviorsManager->setBehaviorsDone(true);
}
}
示例3: testMutate
void testMutate ()
{
String s;
DynamicArray <T> v;
s = "push_back (" + String::fromNumber <int> (numberToMutate) + ")";
beginTestCase (s);
for (std::size_t i = 0; i < numberToMutate; ++i)
v.push_back (T (String::fromNumber (i)));
pass ();
s = "read [] (" + String::fromNumber <int> (numberToMutate) + ")";
beginTestCase (s);
for (std::size_t i = 0; i < numberToMutate; ++i)
expect (v [i].msg == String::fromNumber (i));
s = "write [] (" + String::fromNumber <int> (numberToMutate) + ")";
beginTestCase (s);
for (std::size_t i = 0; i < numberToMutate; ++i)
v [i].msg = "+" + String::fromNumber (i);
pass ();
s = "verify [] (" + String::fromNumber <int> (numberToMutate) + ")";
beginTestCase (s);
for (std::size_t i = 0; i < numberToMutate; ++i)
expect (v [i].msg == String ("+") + String::fromNumber (i));
}
示例4: copyArray
void DynamicArray::copyArray(DynamicArray& copy, const DynamicArray& origin)
{
copy.arr = new int [origin.counter];
copy.counter = 0;
for (int i = 0; i < origin.counter; ++i)
copy.push_back (origin.arr[i]);
}
示例5: getComponentNames
int getComponentNames (ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char **argv){
// getComponentNames stateIdx trajectoryIdx
if( argc != 3 ) return TCL_ERROR;
ControllerEditor* obj = (ControllerEditor*)clientData;
int idx = atoi( argv[1] );
SimBiConState* state = obj->getFramework()->getController()->getState( idx );
if( !state ) return TCL_ERROR;
idx = atoi( argv[2] );
Trajectory* trajectory = state->getTrajectory( idx );
if( !trajectory ) return TCL_ERROR;
DynamicArray<const char*> componentNames;
for( uint i = 0; i < trajectory->components.size(); ++i ) {
char* componentName = new char[ 32 ];
sprintf( componentName, "Component %d", i );
componentNames.push_back( componentName );
}
char* result = stringListToTclList( componentNames );
for( uint i = 0; i < componentNames.size(); ++i )
delete[] componentNames[i];
Tcl_SetResult(interp, result, TCL_DYNAMIC);
return TCL_OK;
}
示例6: getNames
/**
* @brief Returns list of configuration names.
*
* @return
*/
DynamicArray<String> getNames() const noexcept override
{
DynamicArray<String> names;
for (auto attr : m_node.attributes())
names.push_back(attr.name());
return names;
}
示例7: update
void Module::update(simulator::Simulation& simulation, units::Time dt)
{
// Store time step
m_step = dt;
auto _ = measure_time("agglutination", simulator::TimeMeasurementIterationOutput(simulation));
// Get physics world
auto& world = simulation.getWorld();
// Foreach pending bodies
for (const auto& p : m_toJoin)
{
b2WeldJointDef joint;
joint.Initialize(p.bodyA, p.bodyB, p.bodyA->GetWorldCenter());
JointUserData* jUserData = new JointUserData();
jUserData->module = this;
jUserData->Kd = p.dConst;
joint.userData = jUserData;
world.CreateJoint(&joint);
}
m_toJoin.clear();
// Joints to remove
DynamicArray<b2Joint*> toRemove;
// Foreach active joints
for (auto joint = world.GetJointList(); joint != nullptr; joint = joint->GetNext())
{
const JointUserData* jUserData = reinterpret_cast<const JointUserData*>(joint->GetUserData());
// Not our joint
if (jUserData == nullptr)
continue;
if (jUserData->guard != '@')
continue;
std::bernoulli_distribution dist(
getDisassociationPropensity(
m_step,
jUserData->Kd
)
);
if (dist(g_gen))
{
Log::debug("Released: ", joint->GetBodyA(), ", ", joint->GetBodyB());
toRemove.push_back(joint);
delete jUserData;
}
}
// Destroy joints
for (auto joint : toRemove)
world.DestroyJoint(joint);
}
示例8: getSubs
/**
* @brief Returns all sub-configuration with given name.
*
* @param name Sub-configuration name.
*
* @return
*/
DynamicArray<UniquePtr<config::Implementation>> getSubs(StringView name) const noexcept override
{
DynamicArray<UniquePtr<config::Implementation>> res;
// Foreach children
for (const auto& node : m_node.children(name.getData()))
res.push_back(makeUnique<ConfigImplementation>(node.internal_object()));
return res;
}
示例9: getSubNames
/**
* @brief Returns list of sub-configuration names.
*
* @return
*/
DynamicArray<String> getSubNames() const noexcept override
{
DynamicArray<String> names;
for (auto child : m_node.children())
{
if (std::find(names.begin(), names.end(), child.name()) == names.end())
names.push_back(child.name());
}
return names;
}
示例10: draw
void Container::draw(const simulator::Simulation& simulation, render::Context& context)
{
DynamicArray<ViewPtr<Module>> modules;
// Copy modules (view pointer)
for (const auto& module : m_modules)
modules.push_back(module.second);
// Sort modules by rendering order
std::sort(modules.begin(), modules.end(), [](const ViewPtr<Module>& lhs, const ViewPtr<Module>& rhs) {
return lhs->getZOrder() < rhs->getZOrder();
});
// Render modules
for (auto& module : modules)
module->draw(simulation, context);
}
示例11: update
void Container::update(simulator::Simulation& simulation, units::Time dt)
{
DynamicArray<ViewPtr<Module>> modules;
// Copy modules (view pointer)
for (const auto& module : m_modules)
modules.push_back(module.second);
// Sort modules by priority. Cannot be precomputed, because priority can change in previous iteration
std::sort(modules.begin(), modules.end(),
[](const ViewPtr<Module>& lhs, const ViewPtr<Module>& rhs) {
return lhs->getPriority() > rhs->getPriority();
});
// Update modules
for (auto& module : modules)
module->update(simulation, dt);
}
示例12: getStateNames
// Following are wrappers for TCL functions that can access the object
int getStateNames (ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char **argv){
ControllerEditor* obj = (ControllerEditor*)clientData;
SimBiController* controller = obj->getFramework()->getController();
DynamicArray<const char*> stateNames;
uint i = 0;
while( true ) {
SimBiConState* state = controller->getState( i++ );
if( !state ) break;
stateNames.push_back( state->getDescription());
}
char* result = stringListToTclList( stateNames );
Tcl_SetResult(interp, result, TCL_DYNAMIC);
return TCL_OK;
}
示例13: getTrajectoryNames
int getTrajectoryNames (ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char **argv){
// getComponentNames stateIdx
if( argc != 2 ) return TCL_ERROR;
ControllerEditor* obj = (ControllerEditor*)clientData;
int idx = atoi( argv[1] );
SimBiConState* state = obj->getFramework()->getController()->getState( idx );
if( !state ) return TCL_ERROR;
DynamicArray<const char*> trajectoryNames;
for( int i = 0; i < state->getTrajectoryCount(); ++i ) {
Trajectory* trajectory = state->getTrajectory( i );
trajectoryNames.push_back( trajectory->jName );
}
char* result = stringListToTclList( trajectoryNames );
Tcl_SetResult(interp, result, TCL_DYNAMIC);
return TCL_OK;
}
示例14: loadOBJFile
/**
This static method reads an obj file, whose name is sent in as a parameter, and returns a pointer to a GLMesh object that it created based on the file information.
This method throws errors if the file doesn't exist, is not an obj file, etc.
*/
GLMesh* OBJReader::loadOBJFile(const char* fileName){
if (fileName == NULL)
throwError("fileName is NULL.");
// Logger::out()<< "Loading mesh: " << fileName <<std::endl;
FILE* f = fopen(fileName, "r");
if (f == NULL)
throwError("Cannot open file \'%s\'.", fileName);
GLMesh* result = new GLMesh();
result->setOriginalFilename( fileName );
//have a temporary buffer used to read the file line by line...
char buffer[200];
//and this is an array of texture coordinates - the Point3d is a simple data type so I can use the DynamicArray
DynamicArray<Point3d> texCoordinates;
//this variable will keep getting populated with face information
GLIndexedPoly temporaryPolygon;
//this is where it happens.
while (!feof(f)){
//get a line from the file...
fgets(buffer, 200, f);
//see what line it is...
int lineType = getLineType(buffer);
if (lineType == VERTEX_INFO){
//we need to read in the three coordinates - skip over the v
Point3d vertexCoords = readCoordinates(buffer + 1);
result->addVertex(vertexCoords);
}
if (lineType == TEXTURE_INFO){
Point3d texCoords = readCoordinates(buffer + 2);
texCoordinates.push_back(texCoords);
}
if (lineType == FACE_INFO){
temporaryPolygon.indexes.clear();
int vIndex, tIndex;
int flag;
char* tmpPointer = buffer+1;
while (tmpPointer = getNextIndex(tmpPointer, vIndex, tIndex, flag)){
temporaryPolygon.indexes.push_back(vIndex-1);
if (flag & READ_TEXTCOORD_INDEX){
if (tIndex<0)
result->setVertexTexCoordinates(vIndex, texCoordinates[texCoordinates.size()+tIndex]);
else
result->setVertexTexCoordinates(vIndex, texCoordinates[tIndex]);
}
}
if (temporaryPolygon.indexes.size() == 0)
tprintf("Found a polygon with zero vertices.\n");
else
result->addPoly(temporaryPolygon);
}
}
fclose(f);
return result;
}