Changeset 15452


Ignore:
Timestamp:
2013-03-04T00:41:45+01:00 (11 years ago)
Author:
adeas31
Message:
  • Use the QHash with QList for OMC commands hashing instead of filling up the Heap.
Location:
branches/OMEdit/OMEditGUI
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • branches/OMEdit/OMEditGUI/OMC/OMCProxy.cpp

    r15451 r15452  
    4242#include "OMCProxy.h"
    4343#include "../../../Compiler/runtime/config.h"
     44
     45/*!
     46  \class OMCCommandsCache
     47  \brief Stores the list of cached OMC classes.
     48  */
     49/*!
     50  \param pParent - pointer to QObject
     51  */
     52OMCCommandsCache::OMCCommandsCache(QObject *pParent)
     53  : QObject(pParent)
     54{
     55
     56}
     57
     58/*!
     59  Returns the cached OMC command from the hash.
     60  \param className - the name of the class to search for.
     61  \param command - the command to search for.
     62  \return the OMC command
     63  */
     64OMCCommand OMCCommandsCache::getOMCCommand(QString className, QString command)
     65{
     66  if (mOMCCommandsHash.contains(className))
     67  {
     68    QList<OMCCommand> commandsList = mOMCCommandsHash.value(className);
     69    foreach (OMCCommand omcCommand, commandsList)
     70    {
     71      if (omcCommand.mOMCCommand.compare(command) == 0)
     72        return omcCommand;
     73    }
     74  }
     75  return OMCCommand();
     76}
     77
     78/*!
     79  Adds the OMC class name to the hash of cached classes.
     80  \param className - the name of the class.
     81  \param command - the command.
     82  \param commandResult - the command result
     83  */
     84void OMCCommandsCache::addOMCCommand(QString className, QString command, QString commandResult)
     85{
     86  /* if the className is already in commands hash */
     87  if (mOMCCommandsHash.contains(className))
     88  {
     89    QList<OMCCommand> commandsList = mOMCCommandsHash.value(className);
     90    /* if the commands list doesn't contain the command then add it */
     91    bool found = false;
     92    foreach (OMCCommand omcCommand, commandsList)
     93    {
     94      if (omcCommand.mOMCCommand.compare(command) == 0)
     95      {
     96        found = true;
     97        break;
     98      }
     99    }
     100    if (!found)
     101    {
     102      OMCCommand omcCommand;
     103      omcCommand.mOMCCommand = command;
     104      omcCommand.mOMCCommandResult = commandResult;
     105      commandsList.append(omcCommand);
     106      mOMCCommandsHash.insert(className, commandsList);
     107    }
     108  }
     109  else
     110  {
     111    QList<OMCCommand> commandsList;
     112    OMCCommand omcCommand;
     113    omcCommand.mOMCCommand = command;
     114    omcCommand.mOMCCommandResult = commandResult;
     115    commandsList.append(omcCommand);
     116    mOMCCommandsHash.insert(className, commandsList);
     117  }
     118}
    44119
    45120/*!
     
    333408    }
    334409  /* if OMC command is find in the cached OMC commands then use it and return. */
    335   OMCCommand *pOMCCommand = mpOMCCommandsCache->getOMCCommand(className, expression);
    336   if (pOMCCommand)
    337   {
    338     setResult(pOMCCommand->getOMCCommandResult());
     410  OMCCommand pOMCCommand = mpOMCCommandsCache->getOMCCommand(className, expression);
     411  if (!pOMCCommand.mOMCCommandResult.isEmpty())
     412  {
     413    setResult(pOMCCommand.mOMCCommandResult);
    339414    // write command to the commands log.
    340415    QTime commandTime;
  • branches/OMEdit/OMEditGUI/OMC/OMCProxy.h

    r15451 r15452  
    5151class StringHandler;
    5252class OMCCommandsCache;
     53
     54struct OMCCommand
     55{
     56  QString mOMCCommand;
     57  QString mOMCCommandResult;
     58};
     59
     60class OMCCommandsCache : public QObject
     61{
     62  Q_OBJECT
     63public:
     64  OMCCommandsCache(QObject *pParent);
     65  OMCCommand getOMCCommand(QString className, QString command);
     66  void addOMCCommand(QString className, QString command, QString commandResult);
     67private:
     68  QHash<QString, QList<OMCCommand> > mOMCCommandsHash;
     69};
    5370
    5471class OMCProxy : public QObject
  • branches/OMEdit/OMEditGUI/OMEditGUI.pro

    r15449 r15452  
    6161    omc_communication.cc \
    6262    OMC/OMCProxy.cpp \
    63     OMC/OMCCommandsCache.cpp \
    6463    Util/StringHandler.cpp \
    6564    GUI/Widgets/MessagesWidget.cpp \
     
    9291    omc_communication.h \
    9392    OMC/OMCProxy.h \
    94     OMC/OMCCommandsCache.h \
    9593    Util/StringHandler.h \
    9694    GUI/Widgets/MessagesWidget.h \
Note: See TracChangeset for help on using the changeset viewer.