LibOFX

ofx_container_security.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002          ofx_container_security.cpp
00003                              -------------------
00004     copyright            : (C) 2002 by Benoit Gr�goire
00005     email                : benoitg@coeus.ca
00006 ***************************************************************************/
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 
00024 #include <string>
00025 #include "messages.hh"
00026 #include "libofx.h"
00027 #include "ofx_containers.hh"
00028 #include "ofx_utilities.hh"
00029 
00030 extern OfxMainContainer * MainContainer;
00031 
00032 /***************************************************************************
00033  *                     OfxSecurityContainer                                *
00034  ***************************************************************************/
00035 
00036 OfxSecurityContainer::OfxSecurityContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00037   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
00038 {
00039   memset(&data, 0, sizeof(data));
00040   type = "SECURITY";
00041 }
00042 OfxSecurityContainer::~OfxSecurityContainer()
00043 {
00044 }
00045 void OfxSecurityContainer::add_attribute(const string identifier, const string value)
00046 {
00047   if (identifier == "UNIQUEID")
00048   {
00049     strncpy(data.unique_id, value.c_str(), sizeof(data.unique_id));
00050     data.unique_id_valid = true;
00051   }
00052   else if (identifier == "UNIQUEIDTYPE")
00053   {
00054     strncpy(data.unique_id_type, value.c_str(), sizeof(data.unique_id_type));
00055     data.unique_id_type_valid = true;
00056   }
00057   else if (identifier == "SECNAME")
00058   {
00059     strncpy(data.secname, value.c_str(), sizeof(data.secname));
00060     data.secname_valid = true;
00061   }
00062   else if (identifier == "TICKER")
00063   {
00064     strncpy(data.ticker, value.c_str(), sizeof(data.ticker));
00065     data.ticker_valid = true;
00066   }
00067   else if (identifier == "UNITPRICE")
00068   {
00069     data.unitprice = ofxamount_to_double(value);
00070     data.unitprice_valid = true;
00071   }
00072   else if (identifier == "DTASOF")
00073   {
00074     data.date_unitprice = ofxdate_to_time_t(value);
00075     data.date_unitprice_valid = true;
00076   }
00077   else if (identifier == "CURDEF")
00078   {
00079     strncpy(data.currency, value.c_str(), OFX_CURRENCY_LENGTH);
00080     data.currency_valid = true;
00081   }
00082   else if (identifier == "MEMO" || identifier == "MEMO2")
00083   {
00084     strncpy(data.memo, value.c_str(), sizeof(data.memo));
00085     data.memo_valid = true;
00086   }
00087   else
00088   {
00089     /* Redirect unknown identifiers to the base class */
00090     OfxGenericContainer::add_attribute(identifier, value);
00091   }
00092 }
00093 int  OfxSecurityContainer::gen_event()
00094 {
00095   libofx_context->securityCallback(data);
00096   return true;
00097 }
00098 
00099 int  OfxSecurityContainer::add_to_main_tree()
00100 {
00101   if (MainContainer != NULL)
00102   {
00103     return MainContainer->add_container(this);
00104   }
00105   else
00106   {
00107     return false;
00108   }
00109 }
00110