00001
00002
00003
00004
00005
00006
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#ifdef HAVE_CONFIG_H
00020
#include <config.h>
00021
#endif
00022
00023
#include <string>
00024
#include <iostream>
00025
#include "ParserEventGeneratorKit.h"
00026
#include "messages.hh"
00027
#include "libofx.h"
00028
#include "ofx_containers.hh"
00029
00030 OfxMainContainer::OfxMainContainer(LibofxContext *p_libofx_context,
OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00031
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
00032 {
00033
00034
00035
00036
00037 }
00038 OfxMainContainer::~OfxMainContainer()
00039 {
00040
message_out(DEBUG,
"Entering the main container's destructor");
00041 tree<OfxGenericContainer *>::iterator tmp = security_tree.begin();
00042
00043
while(tmp!=security_tree.end())
00044 {
00045
message_out(DEBUG,
"Deleting "+(*tmp)->type);
00046
delete (*tmp);
00047 ++tmp;
00048 }
00049 tmp = account_tree.begin();
00050
while(tmp!=account_tree.end())
00051 {
00052
message_out(DEBUG,
"Deleting "+(*tmp)->type);
00053
delete (*tmp);
00054 ++tmp;
00055 }
00056 }
00057
int OfxMainContainer::add_container(
OfxGenericContainer * container)
00058 {
00059
message_out(DEBUG,
"OfxMainContainer::add_container for element " + container->
tag_identifier +
"; destroying the generic container");
00060
00061 container->
gen_event();
00062
delete container;
00063
return 0;
00064 }
00065
00066
int OfxMainContainer::add_container(
OfxSecurityContainer * container)
00067 {
00068
message_out(DEBUG,
"OfxMainContainer::add_container, adding a security");
00069 security_tree.insert(security_tree.begin(), container);
00070
return true;
00071
00072
00073 }
00074
00075
int OfxMainContainer::add_container(
OfxAccountContainer * container)
00076 {
00077
message_out(DEBUG,
"OfxMainContainer::add_container, adding an account");
00078
if( account_tree.size()==0)
00079 {
00080
message_out(DEBUG,
"OfxMainContainer::add_container, account is the first account");
00081 account_tree.insert(account_tree.begin(), container);
00082 }
00083
else
00084 {
00085
message_out(DEBUG,
"OfxMainContainer::add_container, account is not the first account");
00086 tree<OfxGenericContainer *>::sibling_iterator tmp = account_tree.begin();
00087 tmp += (account_tree.number_of_siblings(tmp))-2;
00088 account_tree.insert_after(tmp, container);
00089 }
00090
return true;
00091 }
00092
00093
int OfxMainContainer::add_container(
OfxStatementContainer * container)
00094 {
00095
message_out(DEBUG,
"OfxMainContainer::add_container, adding a statement");
00096 tree<OfxGenericContainer *>::sibling_iterator tmp = account_tree.begin();
00097
00098 tmp += (account_tree.number_of_siblings(tmp))-2;
00099
00100
if(account_tree.is_valid(tmp))
00101 {
00102
message_out(DEBUG,
"1: tmp is valid, Accounts are present");
00103 tree<OfxGenericContainer *>::iterator child = account_tree.begin(tmp);
00104
if(account_tree.number_of_children(tmp)!=0)
00105 {
00106
message_out(DEBUG,
"There are already children for this account");
00107 account_tree.insert(tmp.begin(), container);
00108
00109 }
00110
else
00111 {
00112
message_out(DEBUG,
"There are no children for this account");
00113 account_tree.append_child(tmp,container);
00114 }
00115 container->
add_account(&( ((
OfxAccountContainer *)(*tmp))->data));
00116
return true;
00117 }
00118
else
00119 {
00120
message_out(ERROR,
"OfxMainContainer::add_container, no accounts are present (tmp is invalid)");
00121
return false;
00122 }
00123 }
00124
00125
int OfxMainContainer::add_container(
OfxTransactionContainer * container)
00126 {
00127
message_out(DEBUG,
"OfxMainContainer::add_container, adding a transaction");
00128
00129
if( account_tree.size()!=0)
00130 {
00131 tree<OfxGenericContainer *>::sibling_iterator tmp = account_tree.begin();
00132
00133 tmp += (account_tree.number_of_siblings(tmp))-2;
00134
if(account_tree.is_valid(tmp))
00135 {
00136
message_out(DEBUG,
"OfxMainContainer::add_container: tmp is valid, Accounts are present");
00137 account_tree.append_child(tmp,container);
00138 container->
add_account(&(((
OfxAccountContainer *)(*tmp))->data));
00139
return true;
00140 }
00141
else
00142 {
00143
message_out(ERROR,
"OfxMainContainer::add_container: tmp is invalid!");
00144
return false;
00145 }
00146 }
00147
else
00148 {
00149
message_out(ERROR,
"OfxMainContainer::add_container: the tree is empty!");
00150
return false;
00151 }
00152 }
00153
00154
int OfxMainContainer::gen_event()
00155 {
00156
message_out(DEBUG,
"Begin walking the trees of the main container to generate events");
00157 tree<OfxGenericContainer *>::iterator tmp = security_tree.begin();
00158
00159
int i = 0;
00160
while(tmp!=security_tree.end())
00161 {
00162
message_out(DEBUG,
"Looping...");
00163
00164 i++;
00165 (*tmp)->gen_event();
00166 ++tmp;
00167 }
00168 tmp = account_tree.begin();
00169
00170 i = 0;
00171
while(tmp!=account_tree.end())
00172 {
00173
00174 i++;
00175 (*tmp)->gen_event();
00176 ++tmp;
00177 }
00178
return true;
00179 }
00180
00181
OfxSecurityData * OfxMainContainer::find_security(string unique_id)
00182 {
00183
message_out(DEBUG,
"OfxMainContainer::find_security() Begin.");
00184
00185 tree<OfxGenericContainer *>::sibling_iterator tmp = security_tree.begin();
00186
OfxSecurityData * retval = NULL;
00187
while(tmp!=security_tree.end()&&retval==NULL)
00188 {
00189
if(((
OfxSecurityContainer*)(*tmp))->data.unique_id==unique_id)
00190 {
message_out(DEBUG,(string)
"Security "+((
OfxSecurityContainer*)(*tmp))->data.unique_id+
" found.");
00191 retval=&((OfxSecurityContainer*)(*tmp))->data;
00192 }
00193 ++tmp;
00194 }
00195
return retval;
00196 }