Skip to content

Commit

Permalink
unifying return value #15949
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Dec 23, 2024
1 parent 9259766 commit 8dbedc6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 38 deletions.
20 changes: 10 additions & 10 deletions src/libsumo/libsumo_typemap.i
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,18 @@ static PyObject* parseSubscriptionMap(const std::map<int, std::shared_ptr<libsum
};

%typemap(out) std::vector<libsumo::TraCIConnection> {
$result = PyList_New($1.size());
$result = PyTuple_New($1.size());
int index = 0;
for (auto iter = $1.begin(); iter != $1.end(); ++iter) {
PyList_SetItem($result, index++, Py_BuildValue("(sNNNsssd)",
iter->approachedLane.c_str(),
PyBool_FromLong(iter->hasPrio),
PyBool_FromLong(iter->isOpen),
PyBool_FromLong(iter->hasFoe),
iter->approachedInternal.c_str(),
iter->state.c_str(),
iter->direction.c_str(),
iter->length));
PyTuple_SetItem($result, index++, Py_BuildValue("(sNNNsssd)",
iter->approachedLane.c_str(),
PyBool_FromLong(iter->hasPrio),
PyBool_FromLong(iter->isOpen),
PyBool_FromLong(iter->hasFoe),
iter->approachedInternal.c_str(),
iter->state.c_str(),
iter->direction.c_str(),
iter->length));
}
};

Expand Down
2 changes: 1 addition & 1 deletion tools/traci/_lane.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _readLinks(result):
length = result.readDouble()
links.append((approachedLane, hasPrio, isOpen, hasFoe,
approachedInternal, state, direction, length))
return links
return tuple(links)


_RETURN_VALUE_FUNC = {tc.LANE_LINKS: _readLinks}
Expand Down
29 changes: 2 additions & 27 deletions tools/traci/_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ._vehicletype import VTypeDomain
from . import constants as tc
from .exceptions import TraCIException, deprecated, alias_param
from ._lane import _readLinks


_legacyGetLeader = True
Expand Down Expand Up @@ -204,32 +205,6 @@ def _readNextStops(result):
return tuple(nextStop)


def _readNextLinks(result):
result.read("!Bi") # Type Compound, Length
nbLinks = result.readInt()
links = []
for _ in range(nbLinks):
result.read("!B") # Type String
approachedLane = result.readString()
result.read("!B") # Type String
approachedInternal = result.readString()
result.read("!B") # Type Byte
hasPrio = bool(result.read("!B")[0])
result.read("!B") # Type Byte
isOpen = bool(result.read("!B")[0])
result.read("!B") # Type Byte
hasFoe = bool(result.read("!B")[0])
result.read("!B") # Type String
state = result.readString()
result.read("!B") # Type String
direction = result.readString()
result.read("!B") # Type Float
length = result.readDouble()
links.append((approachedLane, hasPrio, isOpen, hasFoe,
approachedInternal, state, direction, length))
return tuple(links)


def _readJunctionFoes(result):
result.read("!Bi")
nbJunctionFoes = result.readInt()
Expand Down Expand Up @@ -265,7 +240,7 @@ def _readJunctionFoes(result):
tc.VAR_NEIGHBORS: _readNeighbors,
tc.VAR_NEXT_TLS: _readNextTLS,
tc.VAR_NEXT_STOPS: _readNextStops,
tc.VAR_NEXT_LINKS: _readNextLinks,
tc.VAR_NEXT_LINKS: _readLinks,
tc.VAR_NEXT_STOPS2: _readStopData,
tc.VAR_FOES: _readJunctionFoes,
# ignore num compounds and type int
Expand Down

0 comments on commit 8dbedc6

Please sign in to comment.