LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
DumperStream.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 *
8 * @file DumperStream.cpp
9 * @author Romaric Besancon (romaric.besancon@cea.fr)
10 * @date Fri Jan 21 2011
11 * copyright Copyright (C) 2011-2012 by CEA LIST
12 *
13 ***********************************************************************/
14
15#include "DumperStream.h"
16#include <fstream>
17
18using namespace std;
19
20namespace Lima {
21
22//***********************************************************************
23// constructors and destructors
25m_useHandler(true),
26m_handler(handler),
27m_buffer(0),
28m_out(0)
29{
30// DUMPERLOGINIT;
31// LDEBUG << "DumperStream constructor: initialize buffer" ;
32 // initialize handler stream buffer
33 m_buffer=new HandlerStreamBuf(m_handler);
34 m_out=new ostream(m_buffer);
35 // start communication with handler
36// LDEBUG << "DumperStream constructor: start analysis (handler=" << m_handler << ")";
37 m_handler->startAnalysis();
38}
39
40DumperStream::DumperStream(const std::string& filename, bool append):
41m_useHandler(false),
42m_handler(0),
43m_buffer(0),
44m_out(0)
45{
46 if (append) {
47 m_out=new ofstream(filename.c_str(),ios::app | std::ofstream::binary);
48 }
49 else {
50 m_out=new ofstream(filename.c_str(), std::ofstream::binary);
51 }
52}
53
55{
56 if (m_useHandler) {
57 m_out->flush();
58 m_handler->endAnalysis();
59 delete m_out;
60 m_out=0;
61 // do not delete the handler : allocated outside, should be deleted outside
62 //delete m_handler;
63 //m_handler=0;
64 delete m_buffer;
65 m_buffer=0;
66 }
67 else {
68 static_cast<ofstream*>(m_out)->close();
69 delete m_out;
70 m_out=0;
71 }
72}
73
74//***********************************************************************
75
76} // end namespace
The AbstractAnalysisHandler class defines the callback interface: the functions that are to be define...
virtual void startAnalysis()=0
function called by the LIMA analyzer on start of a new document
virtual void endAnalysis()=0
function called by the LIMA analyzer on the end of a text part that is to be analyzed
DumperStream(AbstractAnalysisHandler *handler)
NAUTITIA.
STL namespace.