#include "tcl.h" #include "TclUtils/EventNumSet.hh" #include void EventNumSet::addEvent(int run, int trigNum) { (*this)[run].insert(trigNum); } int EventNumSet::addEvent(Tcl_Interp *interp, int argc, char *argv[]) { int run, event; if (argc != 3) { Tcl_SetResult(interp, "wrong # of arguments", TCL_VOLATILE); return TCL_ERROR; } if (Tcl_GetInt(interp, argv[1], &run) != TCL_OK) return TCL_ERROR; if (Tcl_GetInt(interp, argv[2], &event) != TCL_OK) return TCL_ERROR; addEvent(run, event); return TCL_OK; } bool EventNumSet::removeEvent(int run, int trigNum) { iterator it = find(run); if (it == end()) return false; std::set::iterator is = it->second.find(trigNum); if (is == it->second.end()) return false; it->second.erase(is); if (it->second.size() == 0) erase(it); return true; } int EventNumSet::removeEvent(Tcl_Interp *interp, int argc, char *argv[]) { int run, event; char *zero = "0", *one = "1"; if (argc != 3) { Tcl_SetResult(interp, "wrong # of arguments", TCL_VOLATILE); return TCL_ERROR; } if (Tcl_GetInt(interp, argv[1], &run) != TCL_OK) return TCL_ERROR; if (Tcl_GetInt(interp, argv[2], &event) != TCL_OK) return TCL_ERROR; bool removed = removeEvent(run, event); Tcl_SetResult(interp, (removed ? one : zero), TCL_VOLATILE); return TCL_OK; } bool EventNumSet::eventInSet(int run, int trigNum) const { const_iterator it = find(run); if (it == end()) return false; std::set::const_iterator is = it->second.find(trigNum); if (is == it->second.end()) return false; return true; } int EventNumSet::eventInSet(Tcl_Interp *interp, int argc, char *argv[]) const { int run, event; char *zero = "0", *one = "1"; if (argc != 3) { Tcl_SetResult(interp, "wrong # of arguments", TCL_VOLATILE); return TCL_ERROR; } if (Tcl_GetInt(interp, argv[1], &run) != TCL_OK) return TCL_ERROR; if (Tcl_GetInt(interp, argv[2], &event) != TCL_OK) return TCL_ERROR; bool inSet = eventInSet(run, event); Tcl_SetResult(interp, (inSet ? one : zero), TCL_VOLATILE); return TCL_OK; } int EventNumSet::setAll(Tcl_Interp *interp, int argc, char *argv[]) { EventNumSet tmpSet; int i, j, run, event, listLen, evLen; char **listElem = NULL, **evElem = NULL; if (argc != 2) { Tcl_SetResult(interp, "wrong # of arguments", TCL_VOLATILE); return TCL_ERROR; } if (Tcl_SplitList(interp, argv[1], &listLen, &listElem) != TCL_OK) goto fail; if (listLen % 2) { Tcl_SetResult(interp, "# of list elements must be even", TCL_VOLATILE); goto fail; } for (i=0; ifirst; ost << ' '; ost << '{'; int count = 0; for (std::set::const_iterator is = it->second.begin(); is != it->second.end(); ++is, ++count) { if (count) ost << ' '; ost << *is; } ost << '}'; } Tcl_SetResult(interp, const_cast(ost.str().c_str()), TCL_VOLATILE); return TCL_OK; }