Changelog update
[public/netxms.git] / src / libnetxms / pa.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** NetXMS Foundation Library
4 ** Copyright (C) 2003-2014 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published
8 ** by the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: pa.cpp
21 **
22 **/
23
24 #include "libnetxms.h"
25
26 /**
27 * Create empty postal address
28 */
29 PostalAddress::PostalAddress()
30 {
31 m_country = NULL;
32 m_city = NULL;
33 m_streetAddress = NULL;
34 m_postcode = NULL;
35 }
36
37 /**
38 * Create postal address with given values
39 */
40 PostalAddress::PostalAddress(const TCHAR *country, const TCHAR *city, const TCHAR *streetAddress, const TCHAR *postcode)
41 {
42 m_country = Trim(_tcsdup_ex(country));
43 m_city = Trim(_tcsdup_ex(city));
44 m_streetAddress = Trim(_tcsdup_ex(streetAddress));
45 m_postcode = Trim(_tcsdup_ex(postcode));
46 }
47
48 /**
49 * Destructor
50 */
51 PostalAddress::~PostalAddress()
52 {
53 free(m_country);
54 free(m_city);
55 free(m_streetAddress);
56 free(m_postcode);
57 }
58
59 /**
60 * Serialize as JSON
61 */
62 json_t *PostalAddress::toJson() const
63 {
64 json_t *root = json_object();
65 json_object_set_new(root, "country", json_string_t(m_country));
66 json_object_set_new(root, "city", json_string_t(m_city));
67 json_object_set_new(root, "streetAddress", json_string_t(m_streetAddress));
68 json_object_set_new(root, "postcode", json_string_t(m_postcode));
69 return root;
70 }