1 /* 2 * "GEDKeeper", the personal genealogical database editor. 3 * Copyright (C) 2009-2021 by Sergey V. Zhdanovskih. 4 * 5 * This file is part of "GEDKeeper". 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 using System; 22 using GDModel.Providers.GEDCOM; 23 24 namespace GDModel 25 { 26 // TODO: remove and work with string idents 27 public enum GEDCOMCharacterSet 28 { 29 csASCII, 30 csANSEL, 31 csUNICODE, 32 csUTF8 33 } 34 35 36 public sealed class GDMHeaderSource : GDMValueTag 37 { 38 public string Version { get; set; } 39 public string ProductName { get; set; } 40 41 GDMHeaderSource()42 public GDMHeaderSource() 43 { 44 SetName(GEDCOMTagType.SOUR); 45 } 46 Clear()47 public override void Clear() 48 { 49 base.Clear(); 50 51 Version = string.Empty; 52 ProductName = string.Empty; 53 } 54 IsEmpty()55 public override bool IsEmpty() 56 { 57 return base.IsEmpty() && string.IsNullOrEmpty(Version) && string.IsNullOrEmpty(ProductName); 58 } 59 } 60 61 62 public sealed class GDMHeaderGEDCOM : GDMTag 63 { 64 public string Version { get; set; } 65 public string Form { get; set; } 66 67 GDMHeaderGEDCOM()68 public GDMHeaderGEDCOM() 69 { 70 SetName(GEDCOMTagType.GEDC); 71 } 72 Clear()73 public override void Clear() 74 { 75 base.Clear(); 76 77 Version = string.Empty; 78 Form = string.Empty; 79 } 80 IsEmpty()81 public override bool IsEmpty() 82 { 83 return base.IsEmpty() && string.IsNullOrEmpty(Version) && string.IsNullOrEmpty(Form); 84 } 85 } 86 87 88 public sealed class GDMHeaderCharSet : GDMTag 89 { 90 private GEDCOMCharacterSet fValue; 91 92 public GEDCOMCharacterSet Value 93 { 94 get { return fValue; } 95 set { fValue = value; } 96 } 97 98 public string Version { get; set; } 99 100 GDMHeaderCharSet()101 public GDMHeaderCharSet() 102 { 103 SetName(GEDCOMTagType.CHAR); 104 } 105 Clear()106 public override void Clear() 107 { 108 base.Clear(); 109 110 Version = string.Empty; 111 } 112 IsEmpty()113 public override bool IsEmpty() 114 { 115 return base.IsEmpty() && string.IsNullOrEmpty(Version); 116 } 117 GetStringValue()118 protected override string GetStringValue() 119 { 120 return GEDCOMUtils.GetCharacterSetStr(fValue); 121 } 122 ParseString(string strValue)123 public override string ParseString(string strValue) 124 { 125 fValue = GEDCOMUtils.GetCharacterSetVal(strValue); 126 return string.Empty; 127 } 128 } 129 130 131 public sealed class GDMHeaderFile : GDMValueTag 132 { 133 public int Revision { get; set; } 134 135 GDMHeaderFile()136 public GDMHeaderFile() 137 { 138 SetName(GEDCOMTagType.FILE); 139 } 140 Clear()141 public override void Clear() 142 { 143 base.Clear(); 144 145 Revision = 0; 146 } 147 IsEmpty()148 public override bool IsEmpty() 149 { 150 return base.IsEmpty() && (Revision == 0); 151 } 152 } 153 154 155 /// <summary> 156 /// 157 /// </summary> 158 public sealed class GDMHeader : GDMTag 159 { 160 private GDMHeaderCharSet fCharacterSet; 161 private string fCopyright; 162 private GDMHeaderFile fFile; 163 private GDMHeaderGEDCOM fGEDCOM; 164 private GDMLanguageID fLanguage; 165 private GDMTextTag fNote; 166 private GDMPlace fPlace; 167 private string fReceivingSystemName; 168 private GDMHeaderSource fSource; 169 private GDMPointer fSubmission; 170 private GDMPointer fSubmitter; 171 private DateTime fTransmissionDateTime; 172 173 174 public GDMHeaderCharSet CharacterSet 175 { 176 get { return fCharacterSet; } 177 } 178 179 public string Copyright 180 { 181 get { return fCopyright; } 182 set { fCopyright = value; } 183 } 184 185 public GDMHeaderFile File 186 { 187 get { return fFile; } 188 } 189 190 public GDMHeaderGEDCOM GEDCOM 191 { 192 get { return fGEDCOM; } 193 } 194 195 public GDMLanguageID Language 196 { 197 get { return fLanguage; } 198 set { fLanguage = value; } 199 } 200 201 public GDMTextTag Note 202 { 203 get { return fNote; } 204 } 205 206 public GDMPlace Place 207 { 208 get { return fPlace; } 209 } 210 211 public string ReceivingSystemName 212 { 213 get { return fReceivingSystemName; } 214 set { fReceivingSystemName = value; } 215 } 216 217 public GDMHeaderSource Source 218 { 219 get { return fSource; } 220 } 221 222 public GDMPointer Submission 223 { 224 get { return fSubmission; } 225 } 226 227 public GDMPointer Submitter 228 { 229 get { return fSubmitter; } 230 } 231 232 public DateTime TransmissionDateTime 233 { 234 get { return fTransmissionDateTime; } 235 set { fTransmissionDateTime = value; } 236 } 237 238 GDMHeader()239 public GDMHeader() 240 { 241 SetName(GEDCOMTagType.HEAD); 242 243 fCharacterSet = new GDMHeaderCharSet(); 244 fFile = new GDMHeaderFile(); 245 fGEDCOM = new GDMHeaderGEDCOM(); 246 fNote = new GDMTextTag((int)GEDCOMTagType.NOTE); 247 fPlace = new GDMPlace(); 248 fSource = new GDMHeaderSource(); 249 fSubmission = new GDMPointer((int)GEDCOMTagType.SUBN, string.Empty); 250 fSubmitter = new GDMPointer((int)GEDCOMTagType.SUBM, string.Empty); 251 } 252 TrimExcess()253 internal override void TrimExcess() 254 { 255 base.TrimExcess(); 256 257 fCharacterSet.TrimExcess(); 258 fFile.TrimExcess(); 259 fGEDCOM.TrimExcess(); 260 fNote.TrimExcess(); 261 fPlace.TrimExcess(); 262 fSource.TrimExcess(); 263 fSubmission.TrimExcess(); 264 fSubmitter.TrimExcess(); 265 } 266 Clear()267 public override void Clear() 268 { 269 base.Clear(); 270 271 fCharacterSet.Clear(); 272 fCopyright = string.Empty; 273 fFile.Clear(); 274 fGEDCOM.Clear(); 275 fLanguage = GDMLanguageID.Unknown; 276 fNote.Clear(); 277 fPlace.Clear(); 278 fReceivingSystemName = string.Empty; 279 fSource.Clear(); 280 fSubmission.Clear(); 281 fSubmitter.Clear(); 282 fTransmissionDateTime = new DateTime(0); 283 } 284 IsEmpty()285 public override bool IsEmpty() 286 { 287 return base.IsEmpty() && fCharacterSet.IsEmpty() && string.IsNullOrEmpty(fCopyright) && fFile.IsEmpty() && 288 fGEDCOM.IsEmpty() && (fLanguage == GDMLanguageID.Unknown) && fNote.IsEmpty() && fPlace.IsEmpty() && 289 string.IsNullOrEmpty(fReceivingSystemName) && fSource.IsEmpty() && fSubmission.IsEmpty() && 290 fSubmitter.IsEmpty() && (fTransmissionDateTime.Equals(GDMChangeDate.ZeroDateTime)); 291 } 292 } 293 } 294