LibOFX
ofx_container_statement.cpp
Go to the documentation of this file.
1/***************************************************************************
2 ofx_container_statement.cpp
3 -------------------
4 copyright : (C) 2002 by Benoit Gr�goire
5 email : benoitg@coeus.ca
6***************************************************************************/
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24#include <string>
25#include "messages.hh"
26#include "libofx.h"
27#include "ofx_containers.hh"
28#include "ofx_utilities.hh"
29
30extern OfxMainContainer * MainContainer;
31
32/***************************************************************************
33 * OfxStatementContainer *
34 ***************************************************************************/
35
36OfxStatementContainer::OfxStatementContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
37 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
38{
39 memset(&data, 0, sizeof(data));
40 type = "STATEMENT";
41}
42OfxStatementContainer::~OfxStatementContainer()
43{
44 /* while(transaction_queue.empty()!=true)
45 {
46 ofx_proc_transaction_cb(transaction_queue.front());
47 transaction_queue.pop();
48 }*/
49}
50void OfxStatementContainer::add_attribute(const string identifier, const string value)
51{
52 if (identifier == "CURDEF")
53 {
54 STRNCPY(data.currency, value);
55 data.currency_valid = !value.empty();
56 }
57 else if (identifier == "MKTGINFO")
58 {
59 ASSIGN_STRNCPY(data.marketing_info, value);
60 }
61 else if (identifier == "DTASOF")
62 {
64 }
65 else if (identifier == "DTSTART")
66 {
68 }
69 else if (identifier == "DTEND")
70 {
71 ASSIGN(data.date_end, ofxdate_to_time_t(value));
72 }
73 else
74 {
75 OfxGenericContainer::add_attribute(identifier, value);
76 }
77}//end OfxStatementContainer::add_attribute()
78
79void OfxStatementContainer::add_balance(OfxBalanceContainer* ptr_balance_container)
80{
81 if (ptr_balance_container->tag_identifier == "LEDGERBAL")
82 {
83 data.ledger_balance = ptr_balance_container->amount;
84 data.ledger_balance_valid = ptr_balance_container->amount_valid;
85 data.ledger_balance_date = ptr_balance_container->date;
86 data.ledger_balance_date_valid = ptr_balance_container->date_valid;
87 }
88 else if (ptr_balance_container->tag_identifier == "AVAILBAL"
89 || ptr_balance_container->tag_identifier == "INV401KBAL")
90 {
91 data.available_balance = ptr_balance_container->amount;
92 data.available_balance_valid = ptr_balance_container->amount_valid;
93 data.available_balance_date = ptr_balance_container->date;
94 data.available_balance_date_valid = ptr_balance_container->date_valid;
95 }
96 else if (ptr_balance_container->tag_identifier == "INVBAL")
97 {
98 data.available_balance = ptr_balance_container->amount;
99 data.available_balance_valid = ptr_balance_container->amount_valid;
100 data.available_balance_date = ptr_balance_container->date;
101 data.available_balance_date_valid = ptr_balance_container->date_valid;
102 data.margin_balance = ptr_balance_container->margin_balance;
103 data.margin_balance_valid = ptr_balance_container->margin_balance_valid;
104 data.short_balance = ptr_balance_container->short_balance;
105 data.short_balance_valid = ptr_balance_container->short_balance_valid;
106 data.buying_power = ptr_balance_container->buying_power;
107 data.buying_power_valid = ptr_balance_container->buying_power_valid;
108 }
109 else
110 {
111 message_out(ERROR, "OfxStatementContainer::add_balance(): the balance has unknown tag_identifier: " + ptr_balance_container->tag_identifier);
112 }
113}
114
115
117{
118 if (MainContainer != NULL)
119 {
120 return MainContainer->add_container(this);
121 }
122 else
123 {
124 return false;
125 }
126}
127
129{
130 libofx_context->statementCallback(data);
131 return true;
132}
133
134
135void OfxStatementContainer::add_account(OfxAccountData * account_data)
136{
137 if (account_data->account_id_valid == true)
138 {
139 data.account_ptr = account_data;
140 ASSIGN_STRNCPY(data.account_id, std::string(account_data->account_id));
141 }
142}
143/*void OfxStatementContainer::add_transaction(const OfxTransactionData transaction_data)
144{
145 transaction_queue.push(transaction_data);
146}*/
Represents the <BALANCE>, <INVBAL> or <INV401KBAL> OFX SGML entity.
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
The root container. Created by the <OFX> OFX element or by the export functions.
virtual int gen_event()
Generate libofx.h events.
virtual int add_to_main_tree()
Add this container to the main tree.
void add_attribute(const string identifier, const string value)
Add data to a container object.
Main header file containing the LibOfx API.
int message_out(OfxMsgType error_type, const string message)
Message output function.
Definition messages.cpp:61
Message IO functionality.
@ ERROR
Definition messages.hh:34
LibOFX internal object code.
time_t ofxdate_to_time_t(const string &ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Various simple functions for type conversion & al.
void STRNCPY(T &dest, const std::string &src)
#define ASSIGN_STRNCPY(DEST, VALUE)
#define ASSIGN(DEST, VALUE)
An abstraction of an account.
Definition libofx.h:277
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition libofx.h:290
double margin_balance
Definition libofx.h:1104
double ledger_balance
Definition libofx.h:1080
time_t date_asof
Definition libofx.h:1087
double buying_power
Definition libofx.h:1112
char currency[OFX_CURRENCY_LENGTH]
Definition libofx.h:1069
time_t available_balance_date
Definition libofx.h:1100
time_t ledger_balance_date
Definition libofx.h:1083
struct OfxAccountData * account_ptr
Definition libofx.h:1074
double short_balance
Definition libofx.h:1108
time_t date_end
Definition libofx.h:1126
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition libofx.h:1072
time_t date_start
Definition libofx.h:1119
double available_balance
Definition libofx.h:1095
char marketing_info[OFX_MARKETING_INFO_LENGTH]
Definition libofx.h:1131