Skip to content

Commit

Permalink
World|MapElement|Line|Plane: Added const overloads for various method…
Browse files Browse the repository at this point in the history
…s of MapElement derived types
  • Loading branch information
danij-deng committed Aug 24, 2013
1 parent 4171c89 commit 47b21df
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 22 deletions.
6 changes: 5 additions & 1 deletion doomsday/client/include/world/bspleaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ class BspLeaf : public de::MapElement
*/
bool hasCluster() const;

/// @copydoc hasCluster()
/**
* Returns @c true iff a sector (cluster) is attributed to the BSP leaf.
*
* Equivalent to @ref hasCluster()
*/
inline bool hasSector() const { return hasCluster(); }

/**
Expand Down
20 changes: 16 additions & 4 deletions doomsday/client/include/world/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,21 @@ class Line : public de::MapElement
/**
* Returns the line side owner of the segment.
*/
Side &lineSide() const;
inline Side &lineSide() { return parent().as<Side>(); }

/// @copydoc lineSide()
inline Side const &lineSide() const { return parent().as<Side>(); }

/**
* Convenient accessor method for returning the line of the owning
* line side.
*
* @see lineSide()
*/
inline Line &line() const { return lineSide().line(); }
inline Line &line() { return lineSide().line(); }

/// @copydoc line()
inline Line const &line() const { return lineSide().line(); }

/**
* Returns the half-edge for the segment.
Expand Down Expand Up @@ -238,7 +244,10 @@ class Line : public de::MapElement
/**
* Returns the Line owner of the side.
*/
Line &line() const;
inline Line &line() { return parent().as<Line>(); }

/// @copydoc line()
inline Line const &line() const { return parent().as<Line>(); }

/**
* Returns the logical identifier for the side (Front or Back).
Expand All @@ -264,7 +273,10 @@ class Line : public de::MapElement
*
* @see lineSideId(), line(), Line::side(),
*/
inline Side &back() const { return line().side(sideId() ^ 1); }
inline Side &back() { return line().side(sideId() ^ 1); }

/// @copydoc back()
inline Side const &back() const { return line().side(sideId() ^ 1); }

/**
* Determines whether "this" side of the respective line should be
Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/include/world/mapelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ class MapElement
*
* @see hasParent(), setParent()
*/
MapElement &parent() const;
MapElement &parent();

/// @copydoc parent()
MapElement const &parent() const;

/**
* Change the parent of the map element.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/api_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void *P_DummyExtraData(void *dummy)
if(P_IsDummy(dummy))
{
MapElement *elem = IN_ELEM(dummy);
return elem->as<DummyData>().extraData;
return elem->maybeAs<DummyData>()->extraData;
}
return 0;
}
Expand Down
12 changes: 1 addition & 11 deletions doomsday/client/src/world/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ Line::Side::Segment::Segment(Line::Side &lineSide, HEdge &hedge)
d(new Instance(&hedge))
{}

Line::Side &Line::Side::Segment::lineSide() const
{
return this->parent().as<Line::Side>();
}

HEdge &Line::Side::Segment::hedge() const
{
DENG_ASSERT(d->hedge != 0);
Expand Down Expand Up @@ -383,11 +378,6 @@ Line::Side::Side(Line &line, Sector *sector)
#endif
}

Line &Line::Side::line() const
{
return this->parent().as<Line>();
}

int Line::Side::sideId() const
{
return &line().front() == this? Line::Front : Line::Back;
Expand Down Expand Up @@ -685,7 +675,7 @@ int Line::Side::property(DmuArgs &args) const
args.setValue(DMT_SIDE_SECTOR, &d->sector, 0);
break;
case DMU_LINE: {
Line *lineAdr = &line();
Line const *lineAdr = &line();
args.setValue(DMT_SIDE_LINE, &lineAdr, 0);
break; }
case DMU_FLAGS:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/linesighttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ DENG2_PIMPL(LineSightTest)
* @todo cleanup: Much unnecessary representation flipping...
* @todo cleanup: Remove front-side assumption.
*/
bool crossLine(LineSide const &side)
bool crossLine(LineSide &side)
{
#define RTOP 0x1 ///< Top range.
#define RBOTTOM 0x2 ///< Bottom range.
Expand Down
7 changes: 6 additions & 1 deletion doomsday/client/src/world/mapelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool MapElement::hasParent() const
return d->parent != 0;
}

MapElement &MapElement::parent() const
MapElement &MapElement::parent()
{
if(d->parent)
{
Expand All @@ -67,6 +67,11 @@ MapElement &MapElement::parent() const
throw MissingParentError("MapElement::parent", "No parent map element is attributed");
}

MapElement const &MapElement::parent() const
{
return const_cast<MapElement *>(this)->parent();
}

void MapElement::setParent(MapElement *newParent)
{
if(d->parent != newParent)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ Plane::Plane(Sector &sector, Vector3f const &normal, coord_t height)

Sector &Plane::sector()
{
return this->parent().as<Sector>();
return parent().as<Sector>();
}

Sector const &Plane::sector() const
{
return const_cast<Sector const &>(const_cast<Plane *>(this)->sector());
return parent().as<Sector>();
}

int Plane::indexInSector() const
Expand Down

0 comments on commit 47b21df

Please sign in to comment.