ofx_container_security.cpp
Go to the documentation of this file.
/***************************************************************************
ofx_container_security.cpp
-------------------
copyright : (C) 2002 by Benoit Gr�goire
email : benoitg@coeus.ca
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#include "messages.hh"
#include "libofx.h"
#include "ofx_containers.hh"
#include "ofx_utilities.hh"
extern OfxMainContainer * MainContainer;
/***************************************************************************
* OfxSecurityContainer *
***************************************************************************/
OfxSecurityContainer::OfxSecurityContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
memset(&data, 0, sizeof(data));
type = "SECURITY";
}
OfxSecurityContainer::~OfxSecurityContainer()
{
}
void OfxSecurityContainer::add_attribute(const string identifier, const string value)
{
if (identifier == "UNIQUEID")
{
strncpy(data.unique_id, value.c_str(), sizeof(data.unique_id));
data.unique_id_valid = true;
}
else if (identifier == "UNIQUEIDTYPE")
{
strncpy(data.unique_id_type, value.c_str(), sizeof(data.unique_id_type));
data.unique_id_type_valid = true;
}
else if (identifier == "SECNAME")
{
strncpy(data.secname, value.c_str(), sizeof(data.secname));
data.secname_valid = true;
}
else if (identifier == "TICKER")
{
strncpy(data.ticker, value.c_str(), sizeof(data.ticker));
data.ticker_valid = true;
}
else if (identifier == "UNITPRICE")
{
data.unitprice = ofxamount_to_double(value);
data.unitprice_valid = true;
}
else if (identifier == "DTASOF")
{
data.date_unitprice = ofxdate_to_time_t(value);
data.date_unitprice_valid = true;
}
else if (identifier == "CURDEF")
{
strncpy(data.currency, value.c_str(), OFX_CURRENCY_LENGTH);
data.currency_valid = true;
}
else if (identifier == "MEMO" || identifier == "MEMO2")
{
strncpy(data.memo, value.c_str(), sizeof(data.memo));
data.memo_valid = true;
}
else if (identifier == "FIID")
{
strncpy(data.fiid, value.c_str(), OFX_FIID_LENGTH);
data.fiid_valid = true;
}
else
{
/* Redirect unknown identifiers to the base class */
OfxGenericContainer::add_attribute(identifier, value);
}
}
int OfxSecurityContainer::gen_event()
{
libofx_context->securityCallback(data);
return true;
}
int OfxSecurityContainer::add_to_main_tree()
{
if (MainContainer != NULL)
{
return MainContainer->add_container(this);
}
else
{
return false;
}
}
OfxGenericContainer
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
Definition: ofx_containers.hh:33
OfxGenericContainer::add_attribute
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: ofx_container_generic.cpp:57
OfxSecurityContainer::add_to_main_tree
virtual int add_to_main_tree()
Add this container to the main tree.
Definition: ofx_container_security.cpp:104
LibofxContext
Definition: context.hh:25
OfxSecurityContainer::gen_event
virtual int gen_event()
Generate libofx.h events.
Definition: ofx_container_security.cpp:98
OfxSecurityData::currency
char currency[OFX_CURRENCY_LENGTH]
Definition: inc/libofx.h:387
OfxSecurityData::memo
char memo[OFX_MEMO2_LENGTH]
Definition: inc/libofx.h:390
OfxSecurityData::fiid
char fiid[OFX_FIID_LENGTH]
Definition: inc/libofx.h:395
OfxSecurityContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: ofx_container_security.cpp:45
OfxSecurityData::unique_id
char unique_id[OFX_UNIQUE_ID_LENGTH]
Definition: inc/libofx.h:360
ofxdate_to_time_t
time_t ofxdate_to_time_t(const string ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Definition: ofx_utilities.cpp:108
ofxamount_to_double
double ofxamount_to_double(const string ofxamount)
Convert OFX amount of money to double float.
Definition: ofx_utilities.cpp:205
OfxSecurityData::date_unitprice
time_t date_unitprice
Definition: inc/libofx.h:382
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxSecurityData::unitprice
double unitprice
Definition: inc/libofx.h:378
OfxGenericContainer::type
string type
Definition: ofx_containers.hh:36
OfxSecurityData::unique_id_type
char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH]
Definition: inc/libofx.h:363
OfxSecurityData::ticker
char ticker[OFX_TICKER_LENGTH]
Definition: inc/libofx.h:375
ofx_containers.hh
LibOFX internal object code.
messages.hh
Message IO functionality.
OfxMainContainer
The root container. Created by the <OFX> OFX element or by the export functions.
Definition: ofx_containers.hh:247
OfxSecurityData::secname
char secname[OFX_SECNAME_LENGTH]
Definition: inc/libofx.h:367