# 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                : bock@step.polymtl.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     strncpy(data.unique_id,value.c_str(), sizeof(data.unique_id));
    00049     data.unique_id_valid = true;
    00050   }
    00051   else if(identifier=="UNIQUEIDTYPE"){
    00052     strncpy(data.unique_id_type,value.c_str(), sizeof(data.unique_id_type));
    00053     data.unique_id_type_valid = true;
    00054   }
    00055   else if(identifier=="SECNAME"){
    00056     strncpy(data.secname,value.c_str(), sizeof(data.secname));
    00057     data.secname_valid = true;
    00058   }
    00059   else if(identifier=="TICKER"){
    00060     strncpy(data.ticker,value.c_str(), sizeof(data.ticker));
    00061     data.ticker_valid = true;
    00062   }
    00063   else if(identifier=="UNITPRICE"){
    00064     data.unitprice=ofxamount_to_double(value);
    00065     data.unitprice_valid = true;
    00066   }
    00067   else if(identifier=="DTASOF"){
    00068     data.date_unitprice = ofxdate_to_time_t(value);
    00069     data.date_unitprice_valid = true;
    00070   }
    00071   else if(identifier=="CURDEF"){
    00072     strncpy(data.currency,value.c_str(),OFX_CURRENCY_LENGTH);
    00073     data.currency_valid=true;
    00074   }
    00075   else if(identifier=="MEMO" || identifier=="MEMO2"){
    00076     strncpy(data.memo,value.c_str(), sizeof(data.memo));
    00077     data.memo_valid = true;
    00078  }
    00079   else{
    00080     /* Redirect unknown identifiers to the base class */
    00081     OfxGenericContainer::add_attribute(identifier, value);
    00082   }
    00083 }
    00084 int  OfxSecurityContainer::gen_event()
    00085 {
    00086   libofx_context->securityCallback(data);
    00087   return true;
    00088 }
    00089
    00090 int  OfxSecurityContainer::add_to_main_tree()
    00091 {
    00092   if(MainContainer != NULL)
    00093     {
    00094       return MainContainer->add_container(this);
    00095     }
    00096   else
    00097     {
    00098       return false;
    00099     }
    00100 }
    00101