LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXBaseObject.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 22.7 % 66 15
Test Date: 2024-11-22 15:46:21 Functions: 23.1 % 13 3

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2003-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MFXBaseObject.cpp
      15              : /// @author  Mathew Robertson
      16              : /// @author  Daniel Krajzewicz
      17              : /// @author  Michael Behrisch
      18              : /// @date    2004-03-19
      19              : ///
      20              : //
      21              : /****************************************************************************/
      22              : 
      23              : 
      24              : /* =========================================================================
      25              :  * included modules
      26              :  * ======================================================================= */
      27              : #include <config.h>
      28              : 
      29              : #define NOMINMAX
      30              : #undef NOMINMAX
      31              : #include "fxheader.h"
      32              : /*
      33              : #include <FXString.h>
      34              : #include <FXHash.h>
      35              : #include <FXStream.h>
      36              : #include <FXSize.h>
      37              : #include <FXPoint.h>
      38              : #include <FXRectangle.h>
      39              : #include <FXRegistry.h>
      40              : #include <FXMutex.h>
      41              : #include <FXApp.h>
      42              : #include <FXWindow.h>
      43              : */
      44              : using namespace FX;
      45              : #include "MFXBaseObject.h"
      46              : 
      47              : using namespace FXEX;
      48              : namespace FXEX {
      49              : 
      50              : FXDEFMAP(MFXBaseObject) MFXBaseObjectMap[] = {
      51              :     FXMAPFUNC(SEL_COMMAND, FXWindow::ID_ENABLE, MFXBaseObject::onCmdEnable),
      52              :     FXMAPFUNC(SEL_COMMAND, FXWindow::ID_DISABLE, MFXBaseObject::onCmdDisable),
      53              :     FXMAPFUNC(SEL_UPDATE, FXWindow::ID_DISABLE, MFXBaseObject::onUpdate),
      54              : };
      55            0 : FXIMPLEMENT(MFXBaseObject, FXObject, MFXBaseObjectMap, ARRAYNUMBER(MFXBaseObjectMap))
      56              : 
      57              : // ctor
      58        15102 : MFXBaseObject::MFXBaseObject(FXObject* tgt, FXSelector sel) : FXObject() {
      59        15102 :     data = nullptr;
      60        15102 :     target = tgt;
      61        15102 :     message = sel;
      62        15102 :     flags = 0;
      63        15102 :     app = FXApp::instance();
      64        15102 :     if (app == nullptr) {
      65            0 :         fxerror("%s: Cannot create object without FXApp object\n", getClassName());
      66              :     }
      67        15102 : }
      68              : 
      69              : // ctor
      70            0 : MFXBaseObject::MFXBaseObject(FXApp* a, FXObject* tgt, FXSelector sel) : FXObject() {
      71            0 :     data = nullptr;
      72            0 :     target = tgt;
      73            0 :     message = sel;
      74            0 :     flags = 0;
      75            0 :     app = a;
      76            0 :     if (app == nullptr) {
      77            0 :         app = FXApp::instance();
      78              :     }
      79            0 :     if (app == nullptr) {
      80            0 :         fxerror("%s: Cannot create object without FXApp object\n", getClassName());
      81              :     }
      82            0 : }
      83              : 
      84              : // free up all resources
      85        15076 : MFXBaseObject::~MFXBaseObject() {
      86        15076 :     if (data != nullptr && data != (void*) - 1) {
      87            0 :         fxerror("%s::~%s - user data is not NULL prior to destruction\n", getClassName(), getClassName());
      88              :     }
      89        15076 :     app = (FXApp*) - 1;
      90        15076 :     target = (FXObject*) - 1;
      91        15076 : }
      92              : 
      93              : // save object to stream
      94            0 : void MFXBaseObject::save(FXStream& store) const {
      95            0 :     FXObject::save(store);
      96            0 :     store << app;
      97            0 :     store << target;
      98            0 :     store << message;
      99            0 :     store << flags;
     100            0 :     store << options;
     101            0 :     store << datalen;
     102            0 :     store.save((FXuchar*)data, (unsigned long)datalen);
     103            0 : }
     104              : 
     105              : // load object from stream
     106            0 : void MFXBaseObject::load(FXStream& store) {
     107            0 :     FXObject::load(store);
     108            0 :     store >> app;
     109            0 :     store >> target;
     110            0 :     store >> message;
     111            0 :     store >> flags;
     112            0 :     store >> options;
     113            0 :     store >> datalen;
     114            0 :     store.load((FXuchar*)data, (unsigned long)datalen);
     115            0 : }
     116              : 
     117              : // this allows MFXBaseObject derived classes to be singletons
     118        30178 : FXApp* MFXBaseObject::getApp() {
     119        30178 :     if (app) {
     120              :         return app;
     121              :     }
     122            0 :     return FXApp::instance();
     123              : }
     124              : 
     125              : // set the readonly flag
     126            0 : void MFXBaseObject::setReadonly(FXbool mode) {
     127            0 :     if (mode) {
     128            0 :         flags |= FLAG_READONLY;
     129              :     } else {
     130            0 :         flags &= ~FLAG_READONLY;
     131              :     }
     132            0 : }
     133              : 
     134              : // handle enable event
     135            0 : long MFXBaseObject::onCmdEnable(FXObject*, FXSelector, void*) {
     136            0 :     enable();
     137            0 :     return 1;
     138              : }
     139              : 
     140              : // handle disable event
     141            0 : long MFXBaseObject::onCmdDisable(FXObject*, FXSelector, void*) {
     142            0 :     disable();
     143            0 :     return 1;
     144              : }
     145              : 
     146              : // handle update event
     147            0 : long MFXBaseObject::onUpdate(FXObject* sender, FXSelector, void*) {
     148            0 :     if (flags & FLAG_ENABLED) {
     149            0 :         sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_ENABLE), nullptr);
     150              :     } else {
     151            0 :         sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_DISABLE), nullptr);
     152              :     }
     153            0 :     return 1;
     154              : }
     155              : 
     156              : }
        

Generated by: LCOV version 2.0-1