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   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   //cerr<<security_tree.size()<<endl;
00133   int i = 0;
00134   while(tmp!=security_tree.end())
00135     {
00136       message_out(DEBUG,"Looping...");
00137       //cerr <<i<<endl;
00138       i++;
00139       (*tmp)->gen_event();
00140       ++tmp;
00141     }
00142   tmp = account_tree.begin();
00143   //cerr<<account_tree.size()<<endl;
00144   i = 0;
00145   while(tmp!=account_tree.end())
00146     {
00147       //cerr<< "i="<<i<<"; depth="<<account_tree.depth(tmp)<<endl;
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 }

Generated on Fri Sep 12 00:35:46 2003 for LibOFX by doxygen 1.3.3