LibOFX: ofx_containers_misc.cpp Source File

Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

# fx-0.8.0/lib/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   libofx_context->statusCallback(data);
    00086 }
    00087 void OfxStatusContainer::add_attribute(const string identifier, const string value)
    00088 {
    00089   ErrorMsg error_msg;
    00090
    00091   if( identifier=="CODE"){
    00092     data.code=atoi(value.c_str());
    00093     error_msg = find_error_msg(data.code);
    00094     data.name = error_msg.name;//memory is already allocated
    00095     data.description = error_msg.description;//memory is already allocated
    00096     data.code_valid = true;
    00097   }
    00098   else if(identifier=="SEVERITY"){
    00099     data.severity_valid = true;
    00100     if(value=="INFO") {
    00101       data.severity=OfxStatusData::INFO;
    00102     }
    00103     else if(value=="WARN") {
    00104       data.severity=OfxStatusData::WARN;
    00105     }
    00106     else if(value=="ERROR") {
    00107       data.severity=OfxStatusData::ERROR;
    00108     }
    00109     else{
    00110       message_out(ERROR, "WRITEME: Unknown severity "+value+" inside a "+type+" container");
    00111       data.severity_valid = false;
    00112     }
    00113   }
    00114   else if((identifier=="MESSAGE")||(identifier=="MESSAGE2")){
    00115     data.server_message=new char[value.length()];
    00116     strcpy(data.server_message,value.c_str());
    00117     data.server_message_valid=true;
    00118   }
    00119   else{
    00120     /* Redirect unknown identifiers to the base class */
    00121     OfxGenericContainer::add_attribute(identifier, value);
    00122   }
    00123 }
    00124
    00125
    00126
    00127 /***************************************************************************
    00128  * OfxBalanceContainer  (does not directly abstract a object in libofx.h)  *
    00129  ***************************************************************************/
    00130
    00131 OfxBalanceContainer::OfxBalanceContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
    00132   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
    00133 {
    00134   amount_valid=false;
    00135   date_valid=false;
    00136   type="BALANCE";
    00137 }
    00138
    00139 OfxBalanceContainer::~OfxBalanceContainer()
    00140 {
    00141   if (parentcontainer->type == "STATEMENT")
    00142     {
    00143       ((OfxStatementContainer*)parentcontainer)->add_balance(this);
    00144     }
    00145   else
    00146     {
    00147       message_out (ERROR,"I completed a " + type + " element, but I havent found a suitable parent to save it");
    00148     }
    00149 }
    00150 void OfxBalanceContainer::add_attribute(const string identifier, const string value)
    00151 {
    00152   if(identifier=="BALAMT"){
    00153     amount=ofxamount_to_double(value);
    00154     amount_valid=true;
    00155   }
    00156   else if(identifier=="DTASOF"){
    00157     date = ofxdate_to_time_t(value);
    00158     date_valid = true;
    00159   }
    00160   else{
    00161     /* Redirect unknown identifiers to the base class */
    00162     OfxGenericContainer::add_attribute(identifier, value);
    00163   }
    00164 }