1 // CalendarObject-Save.cpp - CalendarObject class save functions
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Calendar 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.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "CalendarObject.h"
20 #include "../../common/file.h"
24 CalendarObjectSaveResult CalendarObject::SaveFile(string SaveFilename){
27 string ReceivedStringData = "";
31 FileStream.open(SaveFilename, ofstream::out);
33 if (FileStream.rdstate() & ofstream::failbit){
34 return CALENDAROBJECTSAVE_CANNOTOPEN;
37 if (FileStream.rdstate() & ofstream::badbit){
38 return CALENDAROBJECTSAVE_CANNOTOPEN;
41 // Process the data into a string.
43 CalendarObjectSaveResult SaveResult = CALENDAROBJECTSAVE_UNITTESTFAIL;
44 string SaveStringData;
46 SaveResult = SaveString(&SaveStringData);
48 FileStream.write(SaveStringData.c_str(), SaveStringData.size());
56 CalendarObjectSaveResult CalendarObject::SaveString(string *SaveStringData){
58 *SaveStringData += "BEGIN:VCALENDAR\n";
59 *SaveStringData += "VERSION:2.0\n";
61 // Check if METHOD has a value and print it if it does (and
62 // any token data if there).
64 if (MethodData.size() > 0){
66 if (MethodTokens.size() > 0){
68 *SaveStringData += "METHOD;";
69 *SaveStringData += MethodTokens;
73 *SaveStringData += "METHOD";
77 *SaveStringData += ":";
78 *SaveStringData += MethodData;
79 *SaveStringData += "\n";
83 // Check if CALSCALE has a value and print it if it does (and
84 // any token data if there).
86 if (CalendarScaleData.size() > 0){
88 if (CalendarScaleTokens.size() > 0){
90 *SaveStringData += "CALSCALE;";
91 *SaveStringData += CalendarScaleTokens;
95 *SaveStringData += "CALSCALE";
99 *SaveStringData += ":";
100 *SaveStringData += CalendarScaleData;
101 *SaveStringData += "\n";
105 #if defined(XESTIACAL_UNITTEST)
107 *SaveStringData += "PRODID:-//Xestia//Calendar Unit Testing//KW\n";
111 *SaveStringData += "PRODID:-//Xestia//Calendar Version ";
112 *SaveStringData += XSDCAL_VERSION;
113 *SaveStringData += "//KW\n";
117 SaveObjectData(SaveStringData);
119 *SaveStringData += "END:VCALENDAR";
121 return CALENDAROBJECTSAVE_OK;