rename GridTopology::Create to GridTopology::ArrangeHorizontally
This commit is contained in:
@@ -29,7 +29,7 @@ int main (int argc, char *argv[])
|
||||
// finalize the setup by attaching to each object
|
||||
// in the input array a position and initializing
|
||||
// this position with the calculated coordinates.
|
||||
grid.Create (nodes);
|
||||
grid.ArrangeHorizontally (nodes);
|
||||
|
||||
|
||||
// iterate our nodes and print their position.
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
GridTopology::GridTopology (double xMin, double yMin, uint32_t nCols, double deltaX, double deltaY)
|
||||
GridTopology::GridTopology (double xMin, double yMin, uint32_t n, double deltaX, double deltaY)
|
||||
: m_xMin (xMin),
|
||||
m_yMin (yMin),
|
||||
m_nCols (nCols),
|
||||
m_n (n),
|
||||
m_deltaX (deltaX),
|
||||
m_deltaY (deltaY),
|
||||
m_positionClassId (StaticPosition::cid)
|
||||
@@ -39,7 +39,7 @@ GridTopology::SetPositionModel (ClassId classId)
|
||||
}
|
||||
|
||||
void
|
||||
GridTopology::Create (std::vector<Ptr<Object> > objects)
|
||||
GridTopology::ArrangeHorizontally (std::vector<Ptr<Object> > objects)
|
||||
{
|
||||
double x, y;
|
||||
uint32_t col;
|
||||
@@ -53,7 +53,7 @@ GridTopology::Create (std::vector<Ptr<Object> > objects)
|
||||
object->AddInterface (ComponentManager::Create (m_positionClassId, x, y));
|
||||
x += m_deltaX;
|
||||
col++;
|
||||
if (col == m_nCols)
|
||||
if (col == m_n)
|
||||
{
|
||||
col = 0;
|
||||
x = m_xMin;
|
||||
@@ -62,4 +62,28 @@ GridTopology::Create (std::vector<Ptr<Object> > objects)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GridTopology::ArrangeVertically (std::vector<Ptr<Object> > objects)
|
||||
{
|
||||
double x, y;
|
||||
uint32_t row;
|
||||
x = m_xMin;
|
||||
y = m_yMin;
|
||||
row = 0;
|
||||
for (std::vector<Ptr<Object> >::const_iterator i = objects.begin ();
|
||||
i != objects.end (); i++)
|
||||
{
|
||||
Ptr<Object> object = *i;
|
||||
object->AddInterface (ComponentManager::Create (m_positionClassId, x, y));
|
||||
y += m_deltaY;
|
||||
row++;
|
||||
if (row == m_n)
|
||||
{
|
||||
row = 0;
|
||||
y = m_yMin;
|
||||
x += m_deltaX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -36,7 +36,7 @@ class GridTopology
|
||||
/**
|
||||
* \param xMin the left boundary where the objects will start being arranged.
|
||||
* \param yMin the lower boundary where the objects will start being arranged.
|
||||
* \param nCols number of objects for each row
|
||||
* \param n number of objects for each row or column
|
||||
* \param deltaX distance separating two adjacent objects along the x axis.
|
||||
* \param deltaY distance separating two adjacent objects along the y axis.
|
||||
*
|
||||
@@ -56,14 +56,26 @@ class GridTopology
|
||||
* Attach a position (the type of position is specified through
|
||||
* the ClassId given to SetPositionModel) to each object present
|
||||
* in the input vector and configure its initial location with a set
|
||||
* of coordinates arranged according to a regular rectangular grid.
|
||||
* of coordinates arranged according to a regular rectangular grid,
|
||||
* one row after the other.
|
||||
*/
|
||||
void Create (std::vector<Ptr<Object> > objects);
|
||||
void ArrangeHorizontally (std::vector<Ptr<Object> > objects);
|
||||
|
||||
/**
|
||||
* \param objects a vector of objects
|
||||
*
|
||||
* Attach a position (the type of position is specified through
|
||||
* the ClassId given to SetPositionModel) to each object present
|
||||
* in the input vector and configure its initial location with a set
|
||||
* of coordinates arranged according to a regular rectangular grid,
|
||||
* one column after the other.
|
||||
*/
|
||||
void ArrangeVertically (std::vector<Ptr<Object> > objects);
|
||||
private:
|
||||
GridTopology ();
|
||||
double m_xMin;
|
||||
double m_yMin;
|
||||
uint32_t m_nCols;
|
||||
uint32_t m_n;
|
||||
double m_deltaX;
|
||||
double m_deltaY;
|
||||
ClassId m_positionClassId;
|
||||
|
||||
Reference in New Issue
Block a user