ofx_container_statement.cpp
Go to the documentation of this file.
/***************************************************************************
ofx_container_statement.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 <string>
#include "messages.hh"
#include "libofx.h"
#include "ofx_containers.hh"
#include "ofx_utilities.hh"
extern OfxMainContainer * MainContainer;
/***************************************************************************
* OfxStatementContainer *
***************************************************************************/
OfxStatementContainer::OfxStatementContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, std::string para_tag_identifier):
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
memset(&data, 0, sizeof(data));
type = "STATEMENT";
}
OfxStatementContainer::~OfxStatementContainer()
{
/* while(transaction_queue.empty()!=true)
{
ofx_proc_transaction_cb(transaction_queue.front());
transaction_queue.pop();
}*/
}
void OfxStatementContainer::add_attribute(const std::string identifier, const std::string value)
{
if (identifier == "CURDEF")
{
STRNCPY(data.currency, value);
data.currency_valid = !value.empty();
}
else if (identifier == "MKTGINFO")
{
ASSIGN_STRNCPY(data.marketing_info, value);
}
else if (identifier == "DTASOF")
{
ASSIGN(data.date_asof, ofxdate_to_time_t(value));
}
else if (identifier == "DTSTART")
{
ASSIGN(data.date_start, ofxdate_to_time_t(value));
}
else if (identifier == "DTEND")
{
ASSIGN(data.date_end, ofxdate_to_time_t(value));
}
else
{
OfxGenericContainer::add_attribute(identifier, value);
}
}//end OfxStatementContainer::add_attribute()
void OfxStatementContainer::add_balance(OfxBalanceContainer* ptr_balance_container)
{
if (ptr_balance_container->tag_identifier == "LEDGERBAL")
{
data.ledger_balance = ptr_balance_container->amount;
data.ledger_balance_valid = ptr_balance_container->amount_valid;
data.ledger_balance_date = ptr_balance_container->date;
data.ledger_balance_date_valid = ptr_balance_container->date_valid;
}
else if (ptr_balance_container->tag_identifier == "AVAILBAL"
|| ptr_balance_container->tag_identifier == "INV401KBAL")
{
data.available_balance = ptr_balance_container->amount;
data.available_balance_valid = ptr_balance_container->amount_valid;
data.available_balance_date = ptr_balance_container->date;
data.available_balance_date_valid = ptr_balance_container->date_valid;
}
else if (ptr_balance_container->tag_identifier == "INVBAL")
{
data.available_balance = ptr_balance_container->amount;
data.available_balance_valid = ptr_balance_container->amount_valid;
data.available_balance_date = ptr_balance_container->date;
data.available_balance_date_valid = ptr_balance_container->date_valid;
data.margin_balance = ptr_balance_container->margin_balance;
data.margin_balance_valid = ptr_balance_container->margin_balance_valid;
data.short_balance = ptr_balance_container->short_balance;
data.short_balance_valid = ptr_balance_container->short_balance_valid;
data.buying_power = ptr_balance_container->buying_power;
data.buying_power_valid = ptr_balance_container->buying_power_valid;
}
else
{
message_out(ERROR, "OfxStatementContainer::add_balance(): the balance has unknown tag_identifier: " + ptr_balance_container->tag_identifier);
}
}
int OfxStatementContainer::add_to_main_tree()
{
if (MainContainer != NULL)
{
return MainContainer->add_container(this);
}
else
{
return false;
}
}
int OfxStatementContainer::gen_event()
{
libofx_context->statementCallback(data);
return true;
}
void OfxStatementContainer::add_account(OfxAccountData * account_data)
{
if (account_data->account_id_valid == true)
{
data.account_ptr = account_data;
ASSIGN_STRNCPY(data.account_id, std::string(account_data->account_id));
}
}
/*void OfxStatementContainer::add_transaction(const OfxTransactionData transaction_data)
{
transaction_queue.push(transaction_data);
}*/
OfxGenericContainer::type
std::string type
Definition: ofx_containers.hh:41
ASSIGN
#define ASSIGN(DEST, VALUE)
Definition: ofx_utilities.hh:45
OfxBalanceContainer::date_valid
bool date_valid
Definition: ofx_containers.hh:129
OfxStatementData::available_balance
double available_balance
Definition: inc/libofx.h:1106
ASSIGN_STRNCPY
#define ASSIGN_STRNCPY(DEST, VALUE)
Definition: ofx_utilities.hh:52
OfxStatementData::currency
char currency[OFX_CURRENCY_LENGTH]
Definition: inc/libofx.h:1080
OfxAccountData::account_id
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition: inc/libofx.h:301
OfxStatementData::date_asof
time_t date_asof
Definition: inc/libofx.h:1098
OfxAccountData
An abstraction of an account.
Definition: inc/libofx.h:287
OfxMainContainer
The root container. Created by the <OFX> OFX element or by the export functions.
Definition: ofx_containers.hh:289
OfxBalanceContainer::amount
double amount
Definition: ofx_containers.hh:126
OfxStatementData::date_end
time_t date_end
Definition: inc/libofx.h:1137
OfxStatementData::marketing_info
char marketing_info[OFX_MARKETING_INFO_LENGTH]
Definition: inc/libofx.h:1142
ERROR
@ ERROR
Definition: messages.hh:41
OfxStatementData::date_start
time_t date_start
Definition: inc/libofx.h:1130
OfxStatementData::available_balance_date
time_t available_balance_date
Definition: inc/libofx.h:1111
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxStatementData::short_balance
double short_balance
Definition: inc/libofx.h:1119
OfxGenericContainer
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
Definition: ofx_containers.hh:31
OfxGenericContainer::add_attribute
virtual void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
Definition: ofx_container_generic.cpp:57
OfxStatementData::account_id
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition: inc/libofx.h:1083
LibofxContext
Definition: context.hh:23
OfxBalanceContainer::short_balance_valid
bool short_balance_valid
Definition: ofx_containers.hh:137
OfxStatementData::buying_power
double buying_power
Definition: inc/libofx.h:1123
ofx_containers.hh
LibOFX internal object code.
OfxStatementContainer::add_to_main_tree
virtual int add_to_main_tree()
Add this container to the main tree.
Definition: ofx_container_statement.cpp:116
message_out
int message_out(OfxMsgType error_type, const std::string message)
Message output function.
Definition: messages.cpp:67
OfxBalanceContainer
Represents the <BALANCE>, <INVBAL> or <INV401KBAL> OFX SGML entity.
Definition: ofx_containers.hh:119
OfxStatementContainer::gen_event
virtual int gen_event()
Generate libofx.h events.
Definition: ofx_container_statement.cpp:128
ofxdate_to_time_t
time_t ofxdate_to_time_t(const std::string &ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Definition: ofx_utilities.cpp:68
STRNCPY
void STRNCPY(T &dest, const std::string &src)
Definition: ofx_utilities.hh:35
OfxStatementData::account_ptr
struct OfxAccountData * account_ptr
Definition: inc/libofx.h:1085
OfxStatementData::margin_balance
double margin_balance
Definition: inc/libofx.h:1115
OfxBalanceContainer::margin_balance_valid
bool margin_balance_valid
Definition: ofx_containers.hh:133
OfxStatementData::ledger_balance_date
time_t ledger_balance_date
Definition: inc/libofx.h:1094
OfxBalanceContainer::date
time_t date
Definition: ofx_containers.hh:128
OfxStatementData::ledger_balance
double ledger_balance
Definition: inc/libofx.h:1091
messages.hh
Message IO functionality.
OfxGenericContainer::tag_identifier
std::string tag_identifier
Definition: ofx_containers.hh:42
OfxStatementContainer::add_attribute
void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
Definition: ofx_container_statement.cpp:50