LibOFX

ofx_container_security.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 ofx_container_security.cpp
3 -------------------
4 copyright : (C) 2002 by Benoit Gr�goire
5 email : benoitg@coeus.ca
6 ***************************************************************************/
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <string>
25 #include "messages.hh"
26 #include "libofx.h"
27 #include "ofx_containers.hh"
28 #include "ofx_utilities.hh"
29
30 extern OfxMainContainer * MainContainer;
31
32 /***************************************************************************
33 * OfxSecurityContainer *
34 ***************************************************************************/
35
36 OfxSecurityContainer::OfxSecurityContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
37 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
38 {
39 memset(&data, 0, sizeof(data));
40 type = "SECURITY";
41 }
42 OfxSecurityContainer::~OfxSecurityContainer()
43 {
44 }
45 void OfxSecurityContainer::add_attribute(const string identifier, const string value)
46 {
47 if (identifier == "UNIQUEID")
48 {
49 strncpy(data.unique_id, value.c_str(), sizeof(data.unique_id));
50 data.unique_id_valid = true;
51 }
52 else if (identifier == "UNIQUEIDTYPE")
53 {
54 strncpy(data.unique_id_type, value.c_str(), sizeof(data.unique_id_type));
55 data.unique_id_type_valid = true;
56 }
57 else if (identifier == "SECNAME")
58 {
59 strncpy(data.secname, value.c_str(), sizeof(data.secname));
60 data.secname_valid = true;
61 }
62 else if (identifier == "TICKER")
63 {
64 strncpy(data.ticker, value.c_str(), sizeof(data.ticker));
65 data.ticker_valid = true;
66 }
67 else if (identifier == "UNITPRICE")
68 {
69 data.unitprice = ofxamount_to_double(value);
70 data.unitprice_valid = true;
71 }
72 else if (identifier == "DTASOF")
73 {
74 data.date_unitprice = ofxdate_to_time_t(value);
75 data.date_unitprice_valid = true;
76 }
77 else if (identifier == "CURDEF")
78 {
79 strncpy(data.currency, value.c_str(), OFX_CURRENCY_LENGTH);
80 data.currency_valid = true;
81 }
82 else if (identifier == "MEMO" || identifier == "MEMO2")
83 {
84 strncpy(data.memo, value.c_str(), sizeof(data.memo));
85 data.memo_valid = true;
86 }
87 else if (identifier == "FIID")
88 {
89 strncpy(data.fiid, value.c_str(), OFX_FIID_LENGTH);
90 data.fiid_valid = true;
91 }
92 else
93 {
94 /* Redirect unknown identifiers to the base class */
95 OfxGenericContainer::add_attribute(identifier, value);
96 }
97 }
98 int OfxSecurityContainer::gen_event()
99 {
100 libofx_context->securityCallback(data);
101 return true;
102 }
103
104 int OfxSecurityContainer::add_to_main_tree()
105 {
106 if (MainContainer != NULL)
107 {
108 return MainContainer->add_container(this);
109 }
110 else
111 {
112 return false;
113 }
114 }
115
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
OfxSecurityContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: ofx_container_security.cpp:45
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:131
ofxamount_to_double
double ofxamount_to_double(const string ofxamount)
Convert OFX amount of money to double float.
Definition: ofx_utilities.cpp:230
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxGenericContainer::type
string type
Definition: ofx_containers.hh:36
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