memana/analyzetoolclient/commandlineengine/internal/src/catfilereader.cpp
changeset 0 f0f2b8682603
equal deleted inserted replaced
-1:000000000000 0:f0f2b8682603
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class for reading ascii files in AnalyzeTool.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "../inc/ATCommonDefines.h"
       
    19 #include "../inc/catfilereader.h"
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 // CATFileReader::CATFileReader
       
    23 // Constructor.
       
    24 // -----------------------------------------------------------------------------
       
    25 CATFileReader::CATFileReader()
       
    26 {
       
    27 	LOG_FUNC_ENTRY("CATFileReader::CATFileReader");
       
    28 	m_cDelimiter = '\r'; // default line delimeter
       
    29 }
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CATFileReader::~CATFileReader
       
    33 // Destructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 CATFileReader::~CATFileReader()
       
    36 {
       
    37 	LOG_FUNC_ENTRY("CATFileReader::~CATFileReader");
       
    38 }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CATFileReader::Open
       
    42 // Open / Read file.
       
    43 // -----------------------------------------------------------------------------
       
    44 bool CATFileReader::Open( const char* cFile )
       
    45 {
       
    46 	LOG_FUNC_ENTRY("CATFileReader::Open");
       
    47 	if ( strlen( cFile ) < 1 )
       
    48 	{
       
    49 		LOG_STRING("CATFileReader::Open empty file argument.");
       
    50 		return false;
       
    51 	}
       
    52 	try {
       
    53 		ifstream in;
       
    54 		in.open( cFile, ios::binary );
       
    55 		if ( ! in.good() )
       
    56 			return false;
       
    57 		m_stream << in.rdbuf();
       
    58 		in.close();
       
    59 	}
       
    60 	catch(...)
       
    61 	{
       
    62 		LOG_STRING("CATFileReader::Open unhandled exception.");
       
    63 		return false;
       
    64 	}
       
    65 	return true;
       
    66 }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CATFileReader::Close
       
    70 // Close file.
       
    71 // -----------------------------------------------------------------------------
       
    72 bool CATFileReader::Close( void )
       
    73 {
       
    74 	LOG_FUNC_ENTRY("CATFileReader::Close");
       
    75 	return true;
       
    76 }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CATFileReader::GetLine
       
    80 // Get line from file.
       
    81 // -----------------------------------------------------------------------------
       
    82 bool CATFileReader::GetLine( string& sLine )
       
    83 {
       
    84 	//LOG_FUNC_ENTRY("CATFileReader::GetLine");
       
    85 	char cLine[MAX_LINE_LENGTH];
       
    86 	if ( !m_stream.good() )
       
    87 		return false;
       
    88 	m_stream.getline( cLine, MAX_LINE_LENGTH, m_cDelimiter ); m_stream.get();
       
    89 	sLine = cLine;
       
    90 	return true;
       
    91 }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CATFileReader::SetDelimiter
       
    95 // Set line delimiting character.
       
    96 // -----------------------------------------------------------------------------
       
    97 void CATFileReader::SetDelimiter( char cDelimiter )
       
    98 {
       
    99 	LOG_FUNC_ENTRY("CATFileReader::SetDelimiter");
       
   100 	m_cDelimiter = cDelimiter;
       
   101 }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CATFileReader::GetDelimiter
       
   105 // Get current line delimiting character.
       
   106 // -----------------------------------------------------------------------------
       
   107 char CATFileReader::GetDelimiter() const
       
   108 {
       
   109 	LOG_FUNC_ENTRY("CATFileReader::GetDelimiter()");
       
   110 	return m_cDelimiter;
       
   111 }