File: DataFile.hh

package info (click to toggle)
gri 2.4.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,540 kB
  • ctags: 1,966
  • sloc: cpp: 32,542; lisp: 3,243; perl: 806; makefile: 548; sh: 253
file content (80 lines) | stat: -rw-r--r-- 2,330 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Object for data files
#if !defined(_DataFile_hh_)
#define _DataFile_hh_
#include <string>
#include <vector>		// part of STL
#include <stdio.h>
#include "types.hh"
#include "macro.hh"




#include "CmdFile.hh"

class DataFile
{
public:
    enum type {from_cmdfile, ascii, bin_uchar, bin_16bit, bin_int, bin_float, bin_double, bin_netcdf};
    DataFile() {
	extern vector<CmdFile>  _cmdFILE;
	name = new char [1 + strlen("stdin")];
	if (!name) OUT_OF_MEMORY;
	strcpy(name, "stdin");
	if (_cmdFILE.size() > 0)
	    fp = _cmdFILE.end()->get_fp();
	else 
	    fp = NULL;
	the_type = from_cmdfile;
	line = 0;
	delete_when_close = false;
    }
    DataFile(const DataFile& d) {
	name = new char[1 + strlen(d.get_name())];
	if (!name) OUT_OF_MEMORY;
	strcpy(name, d.get_name());
	fp = d.get_fp();
	netCDF_id = d.get_netCDF_id();
	the_type = d.get_type();
	line = d.get_line();
	delete_when_close = d.get_delete_when_close();
    }
    ~DataFile() {
	delete [] name;
    }
    DataFile& operator=(const DataFile& d) {
	COPY_STRING(name, d.get_name());
	fp = d.get_fp();
	netCDF_id = d.get_netCDF_id();
	the_type = d.get_type();
	line = d.get_line();
	delete_when_close = d.get_delete_when_close();
	return *this;
    }
    void set_name(const char *new_name) {
	COPY_STRING(name, new_name);
    }
    void set_fp(FILE *new_fp)           {fp = new_fp;}
    void set_netCDF_id(int new_id)      {netCDF_id = new_id;}
    void set_type(type new_type)        {the_type = new_type;}
    void set_line(int new_line)         {line = new_line > 1 ? new_line : 1;}
    void set_delete_when_close(bool d)  {delete_when_close = d;}

    void increment_line()               {line++;}

    char *get_name()                    {return name;}
    const char *get_name()       const  {return name;}
    FILE *get_fp()               const  {return fp;}
    int  get_netCDF_id()         const  {return netCDF_id;}
    type get_type()              const  {return the_type;}
    int get_line()               const  {return line;}
    bool get_delete_when_close() const  {return delete_when_close;}
private:
    char *name;			// name of file, or stdin
    FILE *fp;			// file pointer
    int  netCDF_id;		// only used if FILE_BIN_NETCDF
    type the_type;		// 
    int  line;			// current line number
    bool delete_when_close;	// for open "...|"
};
#endif