LibOFX: ofx_containers_misc.cpp Source File

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

# ofx_containers_misc.cpp

Go to the documentation of this file.

    00001 /***************************************************************************
    00002          ofx_proc_rs.cpp
    00003                              -------------------
    00004     copyright            : (C) 2002 by Benoit Grégoire
    00005     email                : bock@step.polymtl.ca
    00006 ***************************************************************************/
    00013 /***************************************************************************
    00014  *                                                                         *
    00015  *   This program is free software; you can redistribute it and/or modify  *
    00016  *   it under the terms of the GNU General Public License as published by  *
    00017  *   the Free Software Foundation; either version 2 of the License, or     *
    00018  *   (at your option) any later version.                                   *
    00019  *                                                                         *
    00020  ***************************************************************************/
    00021
    00022 #ifdef HAVE_CONFIG_H
    00023 #include <config.h>
    00024 #endif
    00025
    00026 #include <iostream>
    00027 #include <stdlib.h>
    00028 #include <string>
    00029 #include "messages.hh"
    00030 #include "libofx.h"
    00031 #include "ofx_error_msg.hh"
    00032 #include "ofx_utilities.hh"
    00033 #include "ofx_containers.hh"
    00034
    00035 extern OfxMainContainer * MainContainer;
    00036
    00037 /***************************************************************************
    00038  *                         OfxDummyContainer                               *
    00039  ***************************************************************************/
    00040
    00041 OfxDummyContainer::OfxDummyContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
    00042   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
    00043 {
    00044   type="DUMMY";
    00045   message_out(INFO, "Created OfxDummyContainer to hold unsupported aggregate "+para_tag_identifier);
    00046 }
    00047 void OfxDummyContainer::add_attribute(const string identifier, const string value)
    00048 {
    00049   message_out(DEBUG, "OfxDummyContainer for "+tag_identifier+" ignored a "+identifier+" ("+value+")");
    00050 }
    00051
    00052 /***************************************************************************
    00053  *                         OfxPushUpContainer                              *
    00054  ***************************************************************************/
    00055
    00056 OfxPushUpContainer::OfxPushUpContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
    00057   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
    00058 {
    00059   type="PUSHUP";
    00060   message_out(DEBUG, "Created OfxPushUpContainer to hold aggregate "+tag_identifier);
    00061 }
    00062 void OfxPushUpContainer::add_attribute(const string identifier, const string value)
    00063 {
    00064   //message_out(DEBUG, "OfxPushUpContainer for "+tag_identifier+" will push up a "+identifier+" ("+value+") to a "+ parentcontainer->type + " container");
    00065   parentcontainer->add_attribute(identifier, value);
    00066 }
    00067
    00068 /***************************************************************************
    00069  *                         OfxStatusContainer                              *
    00070  ***************************************************************************/
    00071
    00072 OfxStatusContainer::OfxStatusContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
    00073   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
    00074 {
    00075   memset(&data,0,sizeof(data));
    00076   type="STATUS";
    00077   if (parentcontainer!=NULL){
    00078     strncpy(data.ofx_element_name, parentcontainer->tag_identifier.c_str(), OFX_ELEMENT_NAME_LENGTH);
    00079     data.ofx_element_name_valid=true;
    00080   }
    00081
    00082 }
    00083 OfxStatusContainer::~OfxStatusContainer()
    00084 {
    00085   message_out(DEBUG,"Entering the status's container's destructor");
    00086
    00087   libofx_context->statusCallback(data);
    00088
    00089   if ( data.server_message_valid )
    00090     delete [] data.server_message;
    00091 }
    00092
    00093 void OfxStatusContainer::add_attribute(const string identifier, const string value)
    00094 {
    00095   ErrorMsg error_msg;
    00096
    00097   if( identifier=="CODE"){
    00098     data.code=atoi(value.c_str());
    00099     error_msg = find_error_msg(data.code);
    00100     data.name = error_msg.name;//memory is already allocated
    00101     data.description = error_msg.description;//memory is already allocated
    00102     data.code_valid = true;
    00103   }
    00104   else if(identifier=="SEVERITY"){
    00105     data.severity_valid = true;
    00106     if(value=="INFO") {
    00107       data.severity=OfxStatusData::INFO;
    00108     }
    00109     else if(value=="WARN") {
    00110       data.severity=OfxStatusData::WARN;
    00111     }
    00112     else if(value=="ERROR") {
    00113       data.severity=OfxStatusData::ERROR;
    00114     }
    00115     else{
    00116       message_out(ERROR, "WRITEME: Unknown severity "+value+" inside a "+type+" container");
    00117       data.severity_valid = false;
    00118     }
    00119   }
    00120   else if((identifier=="MESSAGE")||(identifier=="MESSAGE2")){
    00121     data.server_message=new char[value.length()+1];
    00122     strcpy(data.server_message,value.c_str());
    00123     data.server_message_valid=true;
    00124   }
    00125   else{
    00126     /* Redirect unknown identifiers to the base class */
    00127     OfxGenericContainer::add_attribute(identifier, value);
    00128   }
    00129 }
    00130
    00131
    00132
    00133 /***************************************************************************
    00134  * OfxBalanceContainer  (does not directly abstract a object in libofx.h)  *
    00135  ***************************************************************************/
    00136
    00137 OfxBalanceContainer::OfxBalanceContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
    00138   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
    00139 {
    00140   amount_valid=false;
    00141   date_valid=false;
    00142   type="BALANCE";
    00143 }
    00144
    00145 OfxBalanceContainer::~OfxBalanceContainer()
    00146 {
    00147   if (parentcontainer->type == "STATEMENT")
    00148     {
    00149       ((OfxStatementContainer*)parentcontainer)->add_balance(this);
    00150     }
    00151   else
    00152     {
    00153       message_out (ERROR,"I completed a " + type + " element, but I havent found a suitable parent to save it");
    00154     }
    00155 }
    00156 void OfxBalanceContainer::add_attribute(const string identifier, const string value)
    00157 {
    00158   if(identifier=="BALAMT"){
    00159     amount=ofxamount_to_double(value);
    00160     amount_valid=true;
    00161   }
    00162   else if(identifier=="DTASOF"){
    00163     date = ofxdate_to_time_t(value);
    00164     date_valid = true;
    00165   }
    00166   else{
    00167     /* Redirect unknown identifiers to the base class */
    00168     OfxGenericContainer::add_attribute(identifier, value);
    00169   }
    00170 }