Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

list_polld.h

Go to the documentation of this file.
00001 /*
00002  * MAX : list_polld.h, Sam Dez 29 19:53:27 CET 2001 -sg
00003  * 
00004  * THIS IS THE LIST FILE OF VER 2.0 !!!!
00005  * 
00006  * This file is part of Max data acquisition software
00007  * Copyright (C) 1997,98 Christian Rosen
00008  *
00009  * Max is free software; you can redistribute it and/or modify it
00010  * under the terms of the version 2 of GNU General Public License as
00011  * published by the Free Software Foundation.
00012  *
00013  * Max is distributed in the hope that it will be useful, but WITHOUT
00014  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016  * for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * (see the file COPYING) in this directory; if not, write to the
00020  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021  */
00022 
00023 //list header file contains class declaration for list class
00024 //the list class stores the device parameters which can be seen and edited
00025 //in the listbox
00026 //it also provides all functions to access it
00027 
00028 #ifndef LIST_H
00029 #define LIST_H
00030 
00031 #include "packet.h"
00032 
00033 #include <iostream.h>
00034 #include <assert.h>
00035 #include <string.h>
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <stdlib.h>
00039 
00040 //STL includes
00041 #include <string>
00042 
00043 #include <qstring.h>
00044 #include <qlist.h>
00045 
00046 
00047 /*
00048  *store the properties of all plot statements in an additional list
00049  *to initialize the plotwindows with it
00050  *determine the properties of the plotwindows for all variables
00051  *to be plotted, if data is not given, set default values from
00052  *definitions.h
00053  */
00054 class PlotProps {
00055 public :
00056   friend class Plot;
00057   PlotProps (char *dev = "no_name",char *var="no_name",
00058              int in =0,int prio=0,bool p=FALSE,bool s=FALSE) {
00059       dev_name = new char[strlen(dev)+1];
00060     assert( dev_name != 0);
00061     strcpy(dev_name,dev);
00062     var_name = new char[strlen(var)+1];
00063     assert( var_name !=0);
00064     strcpy(var_name,var);
00065     priority  = prio;
00066     indx      = in;
00067     plotflag  = p;
00068     storeflag = s;
00069     InitPlotOptions();
00070     marker = FALSE;
00071   }
00072   ~PlotProps() {
00073     if (dev_name)
00074       delete dev_name;
00075     if (var_name)       
00076       delete var_name;
00077   }
00078   //these are all plot properties the user can set in the initfile
00079   //thew plotwindows are then initialized with this data
00080   //see also definitions.h and plot.h
00081    int    indx;       //number of var with plotlag == TRUE in list
00082   //this index is equal to the variable index received from polling deamon
00083   //if storeflag == FALSE then  index = -1
00084   //if plotflag is == FALSE -> discard the data and don't plot it
00085   int priority;
00086   char * dev_name;
00087   char * var_name;
00088   bool   plotflag;   //really plot it or discard queued potdata ?
00089   bool   storeflag;  //is it present in the database of measured data?
00090   PlotSettings Ps;   //structure holds all Plotoptions -> see : packet.h
00091   bool   marker;     //used for finding the right plotwindow
00092 private: //these are priority of this device
00093   //set all options to default values from the file definitions.h
00094   void InitPlotOptions(void) {
00095     Ps.pminx        = P_MIN_SIZE_X;
00096     Ps.pminy        = P_MIN_SIZE_Y;
00097     Ps.pleftborder  = P_LEFT_BORDER;
00098     Ps.pupperborder = P_UPPER_BORDER;
00099     Ps.pdefsizex    = P_DEF_SIZE_X;
00100     Ps.pdefsizey    = P_DEF_SIZE_Y;
00101     Ps.xticks       = X_TICKS;
00102     Ps.yticks       = Y_TICKS;
00103     Ps.ticksize     = TICKSIZE;
00104     Ps.tickpos      = TICKPOS;
00105     Ps.tickposx     = TICKPOS_X;
00106     Ps.as_interval  = AS_INTERVAL;
00107     Ps.yupper       = Y_UPPER_LIMIT;
00108     Ps.ylower       = Y_LOWER_LIMIT;
00109     Ps.autoscale    = AUTOSCALE;
00110     Ps.hgridlines   = HGRIDLINES;
00111     Ps.vgridlines   = VGRIDLINES;
00112   }
00113 };
00114 
00115 
00116 //the data_type flag contains the variable type of the save variable
00117 // -> see : List::get_data_type(char *)
00118 //this is neccessary to determine the type for saving the data
00119 //(overloading doesn't work here) -> But, I don't need this routine anymore
00120 //Scheduler::store(var) now sets up an array during first measurement cycle to store data types
00121 //look there to figure that out
00122 //IMPROVEMENT :
00123 //BUT ADD TEMPLATE LIST CLASS TO REMOVE SWITCH STATEMENTS IN GETSTRING AND
00124 // GETALLDEVICEPARAMETERS functions
00125 //
00126 //the following class contains one element of the linked list of device parameters
00127 class Element {
00128  friend class List;
00129 public:
00130 
00131 private:
00132 //private Konstructor for int var
00133   Element(int W, const char *device, const char *var,int flag,int data_type,
00134         int x=0,int y=0, Element *E = 0) {
00135     i_var       = W;
00136     next        = E;
00137     enabled   = flag; //this is the enabled flag !!!! TRUE -> device stores the data
00138     plotflag    = y;   //TRUE is var is plotted
00139     type        = data_type;
00140     storeflag   = x;   //TRUE if variable is a store variable
00141     device_name = device;
00142     var_name    = var;
00143     //    device_name = new char[strlen(device)+1]; //allocate space for strings
00144     //assert(device_name != 0);
00145     //strcpy(device_name,device);
00146     //var_name = new char[strlen(var)+1];
00147     //assert(var_name != 0);
00148     //strcpy(var_name,var);
00149   }
00150 //private Konstructor for double var
00151  Element(double W, const char *device,const char *var,int flag, int data_type,
00152         int x=0,int y=0, Element *E = 0) {
00153     d_var       = W;
00154     next        = E;
00155     enabled     = flag; //this is the enabled flag
00156     plotflag    = y;    //plot ot ?
00157     type        = data_type;
00158     storeflag   = x;  //indicates that thiselemet is a "store" variable
00159     device_name = device;
00160     var_name    = var;
00161     //device_name = device;
00162     //var_name  = var;
00163     //    device_name = new char[strlen(device)+1];
00164     //assert(device_name != 0);
00165     //strcpy(device_name,device);
00166     //    var_name = new char[strlen(var)+1];
00167     //assert(var_name != 0);
00168     //strcpy(var_name,var);
00169  }      
00170   ~Element() {
00171     device_name.~string();
00172     var_name.~string(); 
00173     /*if (device_name)
00174       delete device_name;
00175      if (var_name)
00176      delete var_name;*/
00177   }
00178   string   device_name;
00179   string   var_name;     //data ist a reserved word for a variable name
00180   int      enabled;    //if that is nonzero the according variable
00181   //is saved to disk and can be plotted
00182   //1 = int,2 = double, 3 =char, 4 = string
00183   int      i_var;
00184   double   d_var;
00185   char     c_var;
00186   char *s_var;
00187   Element  *next;
00188   int       type;      //type flag 1 = int,2 = double, 3 = char, 4 = string
00189   int       storeflag; //TRUE is var is a store variable
00190   int       plotflag;  //TRUE is variable is to be plotted
00191 };
00192 //
00193 //This class represents the list of device data together with the functions to
00194 //access it
00195 class List
00196 {
00197 public:
00198   List()
00199   {
00200     L=0; Buffer_pointer=L;
00201     PlotPropList = new QList<PlotProps>;
00202     PlotPropList -> setAutoDelete(TRUE);
00203     assert(PlotPropList !=0);
00204     ParameterStr = new char[10000];
00205     assert(ParameterStr !=0);
00206   }
00207   ~List() {
00208     remove();
00209     delete PlotPropList;
00210   }
00211   void initialize();
00212   void insert  (int   , char *,char *,int,int ); //insert new data-element
00213   void insert  (double, char *,char *,int,int ); //dito but with double
00214   void append  (int,    char *,char *,int,int,int,int ); //append new data-element (at the end)
00215   void append  (double ,char *,char *,int,int,int,int ); //dito but with double-variable
00216   Element * exist(char *,char *);                //check for deviceName && varName in the list
00217   void SortPlotProperties(void);          //add the actual priorites to the plot properties list
00218   void remove  ();                        //removes complete list from memory
00219   int is_active(char *);                  //returns 1 is char* device_name is an active device,
00220                                           //otherwise -1
00221   int    remove (int );                   //removes specific element from list
00222   int    remove (double );
00223   int    getvar (int *   ,char *,char *); //first  device then var-name
00224   int    getvar (double *,char *,char *); //same for double vars
00225   int    putvar (int     ,char *,char *); //set variable value (int)
00226   int    putvar (double  ,char *,char *); //set variable value (double)
00227   int    varcomp(Element *,char *,char *);
00228   void   putvar(int, int);                //set new variable for element at position i
00229   void   putvar(double, int);
00230   void   putvar( char *,int);
00231   int    enabled(char *,char *);          //return TRUE if this var is enabled
00232   int    plotstatus(int );                //return plotstaus(nostorevar,enabled,plot)
00233   int    getint   (int );                 //return variable of element at position index
00234   double getdouble(int );
00235   char   getchr   (int );
00236   char*  getstr   (int );
00237   char*  get_data_type(char *);           /* returns a string with a list of the
00238          *saved data type of device char
00239          *f.e. : the variables string,double,int
00240          *would return : sdi   *
00241          * needed for the save-routine*/
00242   /*network related functions only in ver 2.0 !!!*/
00243   devDataPacket * GetPacketElement(char *); //return struct packet for socket transfer
00244   devDataPacket * GetNextPacket(void );   //return data element pointed to by BufferPointer
00245   void   ResetHelpPointer(void);         //reset help list pointer to beginning of list
00246   int    AdvanceHelpPointer(void);       //go to next element
00247   /* end */
00248   char*  getAllDeviceParameters(char * ); //returns string containing all data of dev. QString name
00249   void   reset_data_buffer();             //which is needed for parameter file save routine
00250   void   printlist();
00251   int    initlist(char *);                //setup database from initfile, return -1 on error
00252   int    initPlotOptions(FILE *fp,PlotProps *); //returns enabled flag
00253   Element* End_Of_List();
00254   char *  getstring(int);                  //returns string with dev-name par-name value
00255   int    get_type(int );                  //returns type of ith element         
00256   char * get_name(int );                  //return name of device at position i
00257   char * get_var_name(int );              //return var name of device at position i
00258   int    get_store_flag(int );            //return the storeflag out of parameter database
00259   int    get_plot_flag(int);      //check if variable specified by position contains plotdata (ysize)
00260   int    get_enabled_flag(int);
00261   void   set_enabled_flag(int,bool);        //toggle the flags according to user input
00262   void   set_plot_flag(int,bool);         //"switch" on/off a variable
00263   int    get_number_plotvars(char *);     //return number of variables to be plotted
00264   string get_plotvar_namelist(char *);   //defined by "data" statement in initfile
00265                                           //or zero if list is empty or at the end
00266   QList <PlotProps> *PlotPropList;
00267 private:
00268   char *ParameterStr;
00269   int index;    //index for plotvariable
00270   int x,i,y;
00271   Element *L;
00272   Element *BufferPointer,*Buffer_pointer;
00273 };
00274 
00275 #endif
00276 
00277 //Don't write behind the endif line !!
00278 

Generated at Mon Sep 2 18:21:04 2002 for MAX by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001