Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

ofx_container_main.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002          ofx_container_main.cpp 
00003                              -------------------
00004     copyright            : (C) 2002 by Benoit Grégoire
00005     email                : bock@step.polymtl.ca
00006 ***************************************************************************/
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
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 //statement_tree_top=statement_tree.insert(statement_tree_top, NULL);
00035 //security_tree_top=security_tree.insert(security_tree_top, NULL);
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   /* Call gen_event anyway, it could be a status container or similar */
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 }
00070 
00071 int OfxMainContainer::add_container(OfxAccountContainer * container)
00072 {
00073   message_out(DEBUG,"OfxMainContainer::add_container, adding an account");
00074   security_tree.insert(account_tree.end(), container);
00075 }
00076 
00077 int OfxMainContainer::add_container(OfxStatementContainer * container)
00078 {
00079   message_out(DEBUG,"OfxMainContainer::add_container, adding a statement");
00080   tree<OfxGenericContainer *>::sibling_iterator tmp =  account_tree.begin();
00081   tmp += (account_tree.number_of_siblings(account_tree.begin()))-1;
00082   
00083   if(tmp!=account_tree.end())
00084     {
00085       message_out(DEBUG,"1: tmp is valid, Accounts are present");
00086       tree<OfxGenericContainer *>::iterator child = account_tree.begin(tmp);
00087       if(child!=account_tree.end(tmp))
00088         {
00089           message_out(DEBUG,"There are already children for this account");
00090           security_tree.insert(child, container);
00091           
00092         }
00093       else
00094         {
00095           message_out(DEBUG,"There are no children for this account");
00096           security_tree.append_child(tmp,container);
00097         }
00098       container->add_account(&( ((OfxAccountContainer *)(*tmp))->data));
00099       return true;
00100     }
00101   else
00102     {
00103       return false;
00104     }
00105 }
00106 
00107 int OfxMainContainer::add_container(OfxTransactionContainer * container)
00108 {
00109   message_out(DEBUG,"OfxMainContainer::add_container, adding a transaction");
00110   tree<OfxGenericContainer *>::sibling_iterator tmp =  account_tree.begin();
00111   tmp += (account_tree.number_of_siblings(account_tree.begin()))-1;
00112 
00113   if(tmp!=account_tree.end())
00114     {
00115       message_out(DEBUG,"1: tmp is valid, Accounts are present");
00116       security_tree.append_child(tmp,container);
00117       container->add_account(&(((OfxAccountContainer *)(*tmp))->data));
00118       return true;
00119     }
00120   else
00121     {
00122       return false;
00123     }
00124 }
00125 
00126 int  OfxMainContainer::gen_event()
00127 {
00128   message_out(DEBUG,"Begin walking the trees of the main container to generate events");
00129   tree<OfxGenericContainer *>::iterator tmp = security_tree.begin();
00130   //cerr<<security_tree.size()<<endl;
00131   int i = 0;
00132   while(tmp!=security_tree.end())
00133     {
00134       message_out(DEBUG,"Looping...");
00135       //cerr <<i<<endl;
00136       i++;
00137       (*tmp)->gen_event();
00138       ++tmp;
00139     }
00140   tmp = account_tree.begin();
00141   //cerr<<account_tree.size()<<endl;
00142   i = 0;
00143   while(tmp!=account_tree.end())
00144     {
00145       //cerr<< "i="<<i<<"; depth="<<account_tree.depth(tmp)<<endl;
00146       i++;
00147       (*tmp)->gen_event();
00148       ++tmp;
00149     }
00150   return true;
00151 }
00152 
00153 OfxSecurityData *  OfxMainContainer::find_security(string unique_id)
00154 {
00155  message_out(DEBUG,"OfxMainContainer::find_security() Begin.");
00156 
00157   tree<OfxGenericContainer *>::sibling_iterator tmp = security_tree.begin();
00158   OfxSecurityData * retval = NULL;
00159   while(tmp!=security_tree.end()&&retval==NULL)
00160     {
00161       if(((OfxSecurityContainer*)(*tmp))->data.unique_id==unique_id)
00162         { message_out(DEBUG,(string)"Security "+((OfxSecurityContainer*)(*tmp))->data.unique_id+" found.");
00163           retval=&((OfxSecurityContainer*)(*tmp))->data;
00164         }
00165       ++tmp;
00166     }
00167   return retval;
00168 }

Generated on Sun Nov 24 20:26:31 2002 for LibOFX by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002