source: tags/release-1.2.2/src/Outputs/FileCatalogueWriter.cc

Last change on this file was 1070, checked in by MatthewWhiting, 12 years ago

Inserting another base class between CatalogueWriter? and VOTableCatalogueWriter, to handle writing to disk files via ofstream.

File size: 2.8 KB
Line 
1// -----------------------------------------------------------------------
2// FileCatalogueWriter.cc: Writing output catalogues to disk files
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <duchamp/Outputs/FileCatalogueWriter.hh>
29#include <duchamp/Outputs/CatalogueWriter.hh>
30#include <ios>
31#include <iostream>
32#include <fstream>
33namespace duchamp {
34
35  FileCatalogueWriter::FileCatalogueWriter():
36    CatalogueWriter()
37  {
38  }
39
40  FileCatalogueWriter::FileCatalogueWriter(std::string name):
41    CatalogueWriter(name)
42  {
43  }
44
45  FileCatalogueWriter::FileCatalogueWriter(const FileCatalogueWriter& other)
46  {
47    this->operator=(other);
48  }
49
50  FileCatalogueWriter& FileCatalogueWriter::operator= (const FileCatalogueWriter& other)
51  {
52    if(this==&other) return *this;
53    ((CatalogueWriter &) *this) = other;
54    this->itsOpenFlag=false;
55    return *this;
56  }
57 
58  FileCatalogueWriter::~FileCatalogueWriter()
59  {
60    if(this->itsOpenFlag) this->closeCatalogue();
61  }
62
63  bool FileCatalogueWriter::openCatalogue(std::ios_base::openmode mode)
64  {
65    if(this->itsName == ""){
66      DUCHAMPERROR("FileCatalogueWriter","No catalogue name provided");
67      this->itsOpenFlag = false;
68    }
69    else {
70      this->itsFileStream.open(this->itsName.c_str(),mode);
71      this->itsOpenFlag = !this->itsFileStream.fail();
72    }
73    if(!this->itsOpenFlag)
74      DUCHAMPERROR("FileCatalogueWriter","Could not open file \""<<this->itsName<<"\"");
75    return this->itsOpenFlag;
76
77  }
78
79
80
81  bool FileCatalogueWriter::closeCatalogue()
82  {
83    this->itsFileStream.close();
84    if(!this->itsFileStream.fail()) this->itsOpenFlag = false;
85    return !this->itsFileStream.fail();
86  }
87
88
89}
Note: See TracBrowser for help on using the repository browser.