build/libofx-0.10.0/lib/ofx_containers_misc.cpp
Go to the documentation of this file.
/***************************************************************************
ofx_proc_rs.cpp
-------------------
copyright : (C) 2002 by Benoit Grégoire
email : benoitg@coeus.ca
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <stdlib.h>
#include <string>
#include "messages.hh"
#include "libofx.h"
#include "ofx_error_msg.hh"
#include "ofx_utilities.hh"
#include "ofx_containers.hh"
extern OfxMainContainer * MainContainer;
/***************************************************************************
* OfxDummyContainer *
***************************************************************************/
OfxDummyContainer::OfxDummyContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
type = "DUMMY";
message_out(INFO, "Created OfxDummyContainer to hold unsupported aggregate " + para_tag_identifier);
}
void OfxDummyContainer::add_attribute(const string identifier, const string value)
{
message_out(DEBUG, "OfxDummyContainer for " + tag_identifier + " ignored a " + identifier + " (" + value + ")");
}
/***************************************************************************
* OfxPushUpContainer *
***************************************************************************/
OfxPushUpContainer::OfxPushUpContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
type = "PUSHUP";
message_out(DEBUG, "Created OfxPushUpContainer to hold aggregate " + tag_identifier);
}
void OfxPushUpContainer::add_attribute(const string identifier, const string value)
{
//message_out(DEBUG, "OfxPushUpContainer for "+tag_identifier+" will push up a "+identifier+" ("+value+") to a "+ parentcontainer->type + " container");
if (parentcontainer)
parentcontainer->add_attribute(identifier, value);
}
/***************************************************************************
* OfxStatusContainer *
***************************************************************************/
OfxStatusContainer::OfxStatusContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
memset(&data, 0, sizeof(data));
type = "STATUS";
if (parentcontainer != NULL)
{
strncpy(data.ofx_element_name, parentcontainer->tag_identifier.c_str(), OFX_ELEMENT_NAME_LENGTH);
data.ofx_element_name_valid = true;
}
}
OfxStatusContainer::~OfxStatusContainer()
{
message_out(DEBUG, "Entering the status's container's destructor");
libofx_context->statusCallback(data);
if ( data.server_message_valid )
delete [] data.server_message;
}
void OfxStatusContainer::add_attribute(const string identifier, const string value)
{
ErrorMsg error_msg;
if ( identifier == "CODE")
{
data.code = atoi(value.c_str());
error_msg = find_error_msg(data.code);
data.name = error_msg.name;//memory is already allocated
data.description = error_msg.description;//memory is already allocated
data.code_valid = true;
}
else if (identifier == "SEVERITY")
{
data.severity_valid = true;
if (value == "INFO")
{
data.severity = OfxStatusData::INFO;
}
else if (value == "WARN")
{
data.severity = OfxStatusData::WARN;
}
else if (value == "ERROR")
{
data.severity = OfxStatusData::ERROR;
}
else
{
message_out(ERROR, "WRITEME: Unknown severity " + value + " inside a " + type + " container");
data.severity_valid = false;
}
}
else if ((identifier == "MESSAGE") || (identifier == "MESSAGE2"))
{
data.server_message = new char[value.length() + 1];
strcpy(data.server_message, value.c_str());
data.server_message_valid = true;
}
else
{
/* Redirect unknown identifiers to the base class */
OfxGenericContainer::add_attribute(identifier, value);
}
}
/***************************************************************************
* OfxBalanceContainer (does not directly abstract a object in libofx.h) *
***************************************************************************/
OfxBalanceContainer::OfxBalanceContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
amount_valid = false;
date_valid = false;
margin_balance_valid = false;
short_balance_valid = false;
buying_power_valid = false;
type = "BALANCE";
}
OfxBalanceContainer::~OfxBalanceContainer()
{
if (parentcontainer->type == "STATEMENT")
{
((OfxStatementContainer*)parentcontainer)->add_balance(this);
}
else
{
message_out (ERROR, "I completed a " + type + " element, but I haven't found a suitable parent to save it");
}
}
void OfxBalanceContainer::add_attribute(const string identifier, const string value)
{
if (identifier == "BALAMT" ||
identifier == "AVAILCASH" || // from <INVBAL>
identifier == "CASHBAL") // from <INV401KBAL>
{
amount = ofxamount_to_double(value);
amount_valid = true;
}
else if (identifier == "MARGINBALANCE")
{
margin_balance = ofxamount_to_double(value);
margin_balance_valid = true;
}
else if (identifier == "SHORTBALANCE")
{
short_balance = ofxamount_to_double(value);
short_balance_valid = true;
}
else if (identifier == "BUYPOWER")
{
buying_power = ofxamount_to_double(value);
buying_power_valid = true;
}
else if (identifier == "DTASOF")
{
date = ofxdate_to_time_t(value);
date_valid = true;
}
else
{
/* Redirect unknown identifiers to the base class */
OfxGenericContainer::add_attribute(identifier, value);
}
}
/***************************************************************************
* OfxInv401kContainer *
* This container is only used to throw away the multiple possible *
* <DTSTART>, <DTASOF> and <DTEND> elements that can occur under <INV401K> *
* so they don't corrupt the statement dates. *
***************************************************************************/
OfxInv401kContainer::OfxInv401kContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
type = "INV401K";
message_out(INFO, "Created OfxInv401kContainer to hold unsupported aggregate " + para_tag_identifier);
}
void OfxInv401kContainer::add_attribute(const string identifier, const string value)
{
if (identifier == "DTSTART" || identifier == "DTEND" || identifier == "DTASOF")
{
message_out(DEBUG, "OfxInv401kContainer for " + tag_identifier + " ignored a " + identifier + " (" + value + ")");
}
else
{
/* Redirect unknown identifiers to the base class */
OfxGenericContainer::add_attribute(identifier, value);
}
}
ofxamount_to_double
double ofxamount_to_double(const string ofxamount)
Convert OFX amount of money to double float.
Definition: build/libofx-0.10.0/lib/ofx_utilities.cpp:230
OfxInv401kContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_containers_misc.cpp:218
OfxGenericContainer
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:33
INFO
Definition: build/libofx-0.10.0/lib/messages.hh:32
ofx_utilities.hh
Various simple functions for type conversion & al.
ofx_containers.hh
LibOFX internal object code.
OfxStatusData::ERROR
Definition: inc/libofx.h:238
OfxGenericContainer::add_attribute
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_container_generic.cpp:57
OfxStatusData::INFO
Definition: inc/libofx.h:236
LibofxContext
Definition: build/libofx-0.10.0/lib/context.hh:25
ErrorMsg::code
int code
Definition: build/libofx-0.10.0/lib/ofx_error_msg.hh:25
ofxdate_to_time_t
time_t ofxdate_to_time_t(const string ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Definition: build/libofx-0.10.0/lib/ofx_utilities.cpp:131
OfxStatusData::WARN
Definition: inc/libofx.h:237
OfxPushUpContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_containers_misc.cpp:62
message_out
int message_out(OfxMsgType error_type, const string message)
Message output function.
Definition: build/libofx-0.10.0/lib/messages.cpp:61
OfxGenericContainer::tag_identifier
string tag_identifier
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:37
OfxStatementContainer
Represents a statement for either a bank account or a credit card account.
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:157
ofx_error_msg.hh
OFX error code management functionnality.
OfxGenericContainer::type
string type
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:36
messages.hh
Message IO functionality.
OfxStatusContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_containers_misc.cpp:95
OfxDummyContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_containers_misc.cpp:47
DEBUG
Definition: build/libofx-0.10.0/lib/messages.hh:25
find_error_msg
const ErrorMsg find_error_msg(int param_code)
Retreive error code descriptions.
Definition: build/libofx-0.10.0/lib/ofx_error_msg.hh:130
ErrorMsg
An abstraction of an OFX error code sent by an OFX server.
Definition: build/libofx-0.10.0/lib/ofx_error_msg.hh:23
ERROR
Definition: build/libofx-0.10.0/lib/messages.hh:34
OfxMainContainer
The root container. Created by the <OFX> OFX element or by the export functions.
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:291
OfxBalanceContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_containers_misc.cpp:169