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(OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00031 OfxGenericContainer(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 }
00064
00065 int OfxMainContainer::add_container(OfxSecurityContainer * container)
00066 {
00067 message_out(DEBUG,"OfxMainContainer::add_container, adding a security");
00068 security_tree.insert_after(security_tree.end(), container);
00069 return true;
00070 }
00071
00072 int OfxMainContainer::add_container(OfxAccountContainer * container)
00073 {
00074 message_out(DEBUG,"OfxMainContainer::add_container, adding an account");
00075 security_tree.insert(account_tree.end(), container);
00076 return true;
00077 }
00078
00079 int OfxMainContainer::add_container(OfxStatementContainer * container)
00080 {
00081 message_out(DEBUG,"OfxMainContainer::add_container, adding a statement");
00082 tree<OfxGenericContainer *>::sibling_iterator tmp = account_tree.begin();
00083 tmp += (account_tree.number_of_siblings(account_tree.begin()))-1;
00084
00085 if(tmp!=account_tree.end())
00086 {
00087 message_out(DEBUG,"1: tmp is valid, Accounts are present");
00088 tree<OfxGenericContainer *>::iterator child = account_tree.begin(tmp);
00089 if(child!=account_tree.end(tmp))
00090 {
00091 message_out(DEBUG,"There are already children for this account");
00092 security_tree.insert(child, container);
00093
00094 }
00095 else
00096 {
00097 message_out(DEBUG,"There are no children for this account");
00098 security_tree.append_child(tmp,container);
00099 }
00100 container->add_account(&( ((OfxAccountContainer *)(*tmp))->data));
00101 return true;
00102 }
00103 else
00104 {
00105 return false;
00106 }
00107 }
00108
00109 int OfxMainContainer::add_container(OfxTransactionContainer * container)
00110 {
00111 message_out(DEBUG,"OfxMainContainer::add_container, adding a transaction");
00112 tree<OfxGenericContainer *>::sibling_iterator tmp = account_tree.begin();
00113 tmp += (account_tree.number_of_siblings(account_tree.begin()))-1;
00114
00115 if(tmp!=account_tree.end())
00116 {
00117 message_out(DEBUG,"1: tmp is valid, Accounts are present");
00118 security_tree.append_child(tmp,container);
00119 container->add_account(&(((OfxAccountContainer *)(*tmp))->data));
00120 return true;
00121 }
00122 else
00123 {
00124 return false;
00125 }
00126 }
00127
00128 int OfxMainContainer::gen_event()
00129 {
00130 message_out(DEBUG,"Begin walking the trees of the main container to generate events");
00131 tree<OfxGenericContainer *>::iterator tmp = security_tree.begin();
00132
00133 int i = 0;
00134 while(tmp!=security_tree.end())
00135 {
00136 message_out(DEBUG,"Looping...");
00137
00138 i++;
00139 (*tmp)->gen_event();
00140 ++tmp;
00141 }
00142 tmp = account_tree.begin();
00143
00144 i = 0;
00145 while(tmp!=account_tree.end())
00146 {
00147
00148 i++;
00149 (*tmp)->gen_event();
00150 ++tmp;
00151 }
00152 return true;
00153 }
00154
00155 OfxSecurityData * OfxMainContainer::find_security(string unique_id)
00156 {
00157 message_out(DEBUG,"OfxMainContainer::find_security() Begin.");
00158
00159 tree<OfxGenericContainer *>::sibling_iterator tmp = security_tree.begin();
00160 OfxSecurityData * retval = NULL;
00161 while(tmp!=security_tree.end()&&retval==NULL)
00162 {
00163 if(((OfxSecurityContainer*)(*tmp))->data.unique_id==unique_id)
00164 { message_out(DEBUG,(string)"Security "+((OfxSecurityContainer*)(*tmp))->data.unique_id+" found.");
00165 retval=&((OfxSecurityContainer*)(*tmp))->data;
00166 }
00167 ++tmp;
00168 }
00169 return retval;
00170 }