LCOV - code coverage report
Current view: top level - src - analysis.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 53 76 69.7 %
Date: 2015-01-05 16:01:02 Functions: 9 13 69.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 62 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * analysis.cpp - analysis class implementation
       3                 :            :  *
       4                 :            :  *
       5                 :            :  * Copyright (C) 2003-2008 Stefan Jahn <stefan@lkcc.org>
       6                 :            :  *
       7                 :            :  * This is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2, or (at your option)
      10                 :            :  * any later version.
      11                 :            :  *
      12                 :            :  * This software is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this package; see the file COPYING.  If not, write to
      19                 :            :  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
      20                 :            :  * Boston, MA 02110-1301, USA.
      21                 :            :  *
      22                 :            :  * $Id: analysis.cpp 1869 2013-03-06 12:50:21Z crobarcro $
      23                 :            :  *
      24                 :            :  */
      25                 :            : 
      26                 :            :  /*! \file analysis.cpp
      27                 :            :   * \brief Implementation of the analysis class.
      28                 :            :   *
      29                 :            :   * Contains the implementation of the analysis class.
      30                 :            :   *
      31                 :            :   */
      32                 :            : 
      33                 :            : #if HAVE_CONFIG_H
      34                 :            : # include <config.h>
      35                 :            : #endif
      36                 :            : 
      37                 :            : //#include <stdio.h>
      38                 :            : //#include <stdlib.h>
      39                 :            : #include <string.h>
      40                 :            : 
      41                 :            : #include "object.h"
      42                 :            : #include "complex.h"
      43                 :            : #include "sweep.h"
      44                 :            : #include "vector.h"
      45                 :            : #include "strlist.h"
      46                 :            : #include "dataset.h"
      47                 :            : #include "ptrlist.h"
      48                 :            : #include "analysis.h"
      49                 :            : 
      50                 :            : namespace qucs {
      51                 :            : 
      52                 :            : //Constructor. Creates an unnamed instance of the analysis class.
      53                 :        284 : analysis::analysis () : object () {
      54                 :        284 :   data = NULL;
      55                 :        284 :   subnet = NULL;
      56                 :        284 :   env = NULL;
      57                 :        284 :   actions = NULL;
      58                 :        284 :   type = ANALYSIS_UNKNOWN;
      59                 :        284 :   runs = 0;
      60                 :        284 :   progress = true;
      61                 :        284 : }
      62                 :            : 
      63                 :            : // Constructor creates a named instance of the analysis class.
      64                 :          0 : analysis::analysis (char * n) : object (n) {
      65                 :          0 :   data = NULL;
      66                 :          0 :   subnet = NULL;
      67                 :          0 :   env = NULL;
      68                 :          0 :   actions = NULL;
      69                 :          0 :   type = ANALYSIS_UNKNOWN;
      70                 :          0 :   runs = 0;
      71                 :          0 :   progress = true;
      72                 :          0 : }
      73                 :            : 
      74                 :            : // Destructor deletes the analysis class object.
      75                 :        284 : analysis::~analysis () {
      76 [ +  - ][ +  - ]:        284 :   if (actions) delete actions;
         [ +  + ][ +  - ]
      77 [ -  + ][ -  + ]:        387 : }
      78                 :            : 
      79                 :            : /* The copy constructor creates a new instance of the analysis class
      80                 :            :    based on the given analysis object. */
      81                 :          0 : analysis::analysis (analysis & a) : object (a) {
      82                 :          0 :   data = a.data;
      83                 :          0 :   subnet = a.subnet;
      84                 :          0 :   env = a.env;
      85 [ #  # ][ #  # ]:          0 :   actions = a.actions ? new ptrlist<analysis> (*a.actions) : NULL;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      86                 :          0 :   type = a.type;
      87                 :          0 :   runs = a.runs;
      88                 :          0 :   progress = a.progress;
      89                 :          0 : }
      90                 :            : 
      91                 :            : /* This function adds the given analysis to the actions being
      92                 :            :    associated with the current analysis object. */
      93                 :        157 : void analysis::addAnalysis (analysis * a) {
      94 [ +  + ][ +  - ]:        157 :   if (!actions) actions = new ptrlist<analysis> ();
      95                 :        157 :   actions->push_front (a);
      96                 :        157 : }
      97                 :            : 
      98                 :            : /* This function deletes the given analysis from the actions being
      99                 :            :    associated with the current analysis object. */
     100                 :         98 : void analysis::delAnalysis (analysis * a) {
     101         [ +  - ]:         98 :   if (actions != nullptr) {
     102                 :         98 :     actions->remove (a);
     103                 :            :   }
     104                 :         98 : }
     105                 :            : 
     106                 :            : /* The following function creates a sweep object depending on the
     107                 :            :    analysis's properties.  Supported sweep types are: linear,
     108                 :            :    logarithmic, lists and constants. */
     109                 :        160 : sweep * analysis::createSweep (const char * n) {
     110                 :        160 :   sweep * swp = NULL;
     111                 :            :   // get type of sweep
     112                 :        160 :   const char * const type = getPropertyString ("Type");
     113                 :            : 
     114                 :            :   // linearly or logarithmically stepped sweeps
     115 [ +  + ][ +  + ]:        160 :   if (!strcmp (type, "lin") || !strcmp (type, "log")) {
     116                 :        156 :     nr_double_t start = getPropertyDouble ("Start");
     117                 :        156 :     nr_double_t stop = getPropertyDouble ("Stop");
     118                 :        156 :     int points = getPropertyInteger ("Points");
     119         [ +  + ]:        156 :     if (!strcmp (type, "lin")) {
     120         [ +  - ]:        131 :       swp = new linsweep (n);
     121                 :        131 :       ((linsweep *) swp)->create (start, stop, points);
     122                 :            :     }
     123         [ +  - ]:         25 :     else if (!strcmp (type, "log")) {
     124         [ +  - ]:         25 :       swp = new logsweep (n);
     125                 :         25 :       ((logsweep *) swp)->create (start, stop, points);
     126                 :        156 :     }
     127                 :            :   }
     128                 :            : 
     129                 :            :   // lists of values
     130         [ +  - ]:          4 :   else if (!strcmp (type, "list")) {
     131                 :          4 :     vector * values = getPropertyVector ("Values");
     132                 :          4 :     int points = values->getSize ();
     133         [ +  - ]:          4 :     swp = new lstsweep (n);
     134                 :          4 :     ((lstsweep *) swp)->create (points);
     135         [ +  + ]:         20 :     for (int i = 0; i < values->getSize (); i++)
     136         [ +  - ]:         16 :       swp->set (i, real (values->get (i)));
     137                 :            :   }
     138                 :            : 
     139                 :            :   // constant value
     140         [ #  # ]:          0 :   else if (!strcmp (type, "const")) {
     141                 :          0 :     nr_double_t val = getPropertyDouble ("Values");
     142         [ #  # ]:          0 :     swp = new consweep (n);
     143                 :          0 :     ((consweep *) swp)->create (1);
     144                 :          0 :     swp->set (0, val);
     145                 :            :   }
     146                 :            : 
     147                 :        160 :   swp->setParent (this);
     148                 :        160 :   return swp;
     149                 :            : }
     150                 :            : 
     151                 :            : /* Saves the given variable into the dataset.  Creates the dataset
     152                 :            :    vector if necessary. */
     153                 :     515645 : void analysis::saveVariable (const char * n, nr_complex_t z, vector * f) {
     154                 :            :   vector * d;
     155         [ +  + ]:     515645 :   if ((d = data->findVariable (n)) == NULL) {
     156         [ +  - ]:        992 :     d = new vector (n);
     157         [ +  + ]:        992 :     if (f != NULL) {
     158         [ +  - ]:        586 :       d->setDependencies (new strlist ());
     159                 :        586 :       d->getDependencies()->add (f->getName ());
     160                 :            :     }
     161                 :        992 :     d->setOrigin (getName ());
     162                 :        992 :     data->addVariable (d);
     163                 :            :   }
     164                 :     515645 :   d->add (z);
     165                 :     515645 : }
     166                 :            : 
     167                 :            : } // namespace qucs

Generated by: LCOV version 1.11