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

database.h

Go to the documentation of this file.
00001 /*
00002  * MAX : database.h, Sam Dez 29 19:34:06 CET 2001 -sg
00003  *
00004  * This file is part of Max data acquisition software
00005  * Copyright (C) 1998 Christian Rosen
00006  *
00007  * Max is free software; you can redistribute it and/or modify it
00008  * under the terms of the version 2 of GNU General Public License as
00009  * published by the Free Software Foundation.
00010  *
00011  * Max is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00014  * for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * (see the file COPYING) in this directory; if not, write to the
00018  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 
00022 //header file of database class
00023 //this class stores all measured data received by the MainGUI
00024 //and saves them to disk
00025 
00026 #ifndef DATABASE_H
00027 #define DATABASE_H
00028 
00029 #define BACKUP_ARRAY_SIZE MAX_ARRAY_SIZE //size for array to be plotted, rest is truncated
00030                                 
00031 #include <assert.h>
00032 #include <stdarg.h>
00033 #include <string.h>
00034 #include <stdio.h>
00035 
00036 //STL includes
00037 
00038 #include <vector.h>
00039 #include <list.h>
00040 
00041 //lokal includes
00042 
00043 #include "qtincludes.h"
00044 #include "error.h"
00045 #include "data.h"
00046 #include "priority.h"
00047 //
00048 //typelist of measured data for save-routine
00049 //structures needed for save routine
00050 //to determine the variable type for storage to disk
00051 //
00052 typedef struct VarType {
00053   int       type;            //1 = int, 2 = double
00054   };
00055 typedef struct ArrayType {
00056   int       size;
00057   int       type;             //1 = int, 2 = double
00058 };
00059 //
00060 //class definitions for the data base containing the measured data
00061 //the constructor is overloaded, hence different data types can be stored there
00062 //
00063 //Image class -> store linked list of images
00064 //
00065 class ImageListElement {
00066   friend class Database;
00067 public:
00068   QImage Image(void) const { return image; }
00069 private :
00070   ImageListElement(QImage *i,ImageListElement *I = 0) {
00071     image = i->copy();
00072     next  = I;
00073   }
00074   ~ImageListElement() {// delete image;
00075   }
00076   QImage           image;
00077   ImageListElement *next;
00078 };
00079 //
00080 //base class for scalar data (integers and doubles)
00081 //measured data is stored in a vector of this class
00082 //this is faster than a linked list
00083 //this class provides several default constructors for the different data types
00084 //see : Dlist in database.c
00085 //
00086 class Scalar_Vector_Element {
00087   friend class Database;
00088   public  :
00089    ~Scalar_Vector_Element() {   }
00090    Scalar_Vector_Element(int x )     { i_var = x;type =1; }
00091    Scalar_Vector_Element(double x)   { d_var = x;type =2; }
00092   private :
00093    int    type;       //1 = int, 2 = double
00094    int    i_var;
00095    double d_var;
00096 };
00097 //
00098 //base class for linked list of vectors
00099 //this class is used to store the array of int and double in a vector
00100 //see :  Alist in database.c
00101 //
00102 class Array_Vector_Element {
00103  friend class Database;
00104   public  :
00105   ~Array_Vector_Element() {
00106     //i_vec.~vector<int>   i_vec ();    //destroy it
00107     //d_vec.~vector<double>d_vec (); //destroy it
00108   }
00109   Array_Vector_Element(int x[],size_t size) {
00110     type = 1;
00111     i_vec.reserve(size);
00112     for (unsigned int i=0; i< size; i++) i_vec.push_back(x[i]);
00113     //   d_vec = 0;
00114   }
00115   Array_Vector_Element(double x[],size_t size) {
00116     type = 2;
00117     d_vec.reserve(size);                                 //reserve size
00118     for (unsigned int i=0; i< size; i++) d_vec.push_back(x[i]); //copy elements
00119     //i_vec = 0;
00120   }
00121   private :
00122   int            type; //1 = int, 2 = double
00123   vector<int>    i_vec;
00124   vector<double> d_vec;
00125 };
00126 
00127 /****************************************************************************/
00128 /* main header part */
00129 /****************************************************************************/
00130 class Database  {
00131 
00132 public :          //initialize to normal mode with external trigger(=0)
00133   Database();
00134   ~Database();
00135   void init();   
00136   int  maximal_integrations  (void );  //return max_integ al channel number
00137   //
00138   //class functions for database
00139   //
00140   void add_data( int      );
00141   void add_data( double   );
00142   void add_data( char     );
00143   void add_data( char *   );
00144   void add_data( QImage * );
00145   vector<int>    * add_data( int*,int );     //add array of int containing  n elements to ArrayList
00146   vector<double> * add_data( double *, int ); //add integer array, return address of it
00147   void store   ( int      );
00148   void store   ( double   );
00149   void store   ( int *,int);
00150   void store   ( char *   );     //filename for image loading from disk
00151   //
00152   //functions for internal data handling
00153   //
00154   void turn_around(void );
00155   void arrayList_turn_around();
00156   void imageList_turn_around();
00157   void remove       ( void );        
00158   void remove       ( int  );        
00159   void remove_1st   ( void );        
00160   void array_remove_1st( void );     
00161   void array_remove  (int  );        
00162   void printlist    ( void );        //just for debugging purposes
00163   void save_data   (const char *, VarType *,int);   //new save routine
00164   void save_arrays  ( const char *, ArrayType *); //save integer strings
00165   void save_images  ( const char *,int ,char *);
00166   void set_N_Elements (int );       
00167   void set_N_Arrays(int);           
00168   void set_MonMode(bool );          
00169   int  length_of_list( void );
00170   int  length_of_arraylist( void );
00171   int  length_of_imagelist( void );
00172   int  maxarraylength();             //find length of longest array
00173   int  array_empty   ( void );       //return NULL if array is empty
00174   int  database_empty( void );       //return NULL if no data is saved
00175   int  image_empty   ( void );
00176   ImageListElement *end_of_image_list();
00177 private :
00178 //List of measured data packets see : data.cc
00179   //this class also contains functions to convert data to packets
00180   PacketList         *Que;
00181   dataPacket         dat_packet;  //Packet for sending measured data  -> see packet.h
00182   int max_channels;
00183   int max_integrations;
00184   int channels;                 //current channel
00185   int integrations;             //maximum number of integrations per cycle
00186   int priority;                 //actual priority currently called
00187   int stop ;
00188   int s_mode;                   //False if no signals for display are called from scheduler (high speed)
00189   int t_mode;                   //TRUE = external trigger ,FALSE = internal
00190   int device_status;            //return status of devices -> (used by SLOT_measure only)
00191   uint period;                  //delay for internal trigger contains ms
00192   bool busy;                    //busy flag to block parallel measurements
00193   //
00194   //elements for database functions
00195   //
00196   QList <Scalar_Vector_Element> Dlist; 
00197   QList <Array_Vector_Element>  Alist; 
00198   vector<VarType> *Sc_Data;
00199   ImageListElement *Image;      //Pointer to element of image list
00200   //
00201   //
00202   char              *typelist;
00203   int               var_index;         //index off all "stored" variables
00204   int               temp_var_index;
00205   int               element_counter;   //contains the numberof measured data stored by device functions
00206   int               array_counter;     //counter for array-backup array
00207   int               temp_counter;      //temp counter for add_data function
00208   int               array_temp_counter;//temp counter for array add_data function
00209   int               maxarraysize;
00210   int               varcounter;        
00211   int               arraycounter;      
00212   bool              monitor_mode;
00213   int               *z;
00214   double            *zd;
00215   //end of database variables
00216 };
00217 
00218 #endif
00219 //don't write  behind the endif

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