/[ghosts]/ghosts/gedcomparser/src/GEDCOMParser/DateManagement/DateValue.cpp
ViewVC logotype

Diff of /ghosts/gedcomparser/src/GEDCOMParser/DateManagement/DateValue.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by cpcp, Wed Oct 23 19:21:41 2002 UTC revision 1.2 by cpcp, Tue Nov 12 21:25:21 2002 UTC
# Line 0  Line 1 
1    /**
2        Copyright 2002 Cyril Picard
3    
4        This file is part of the GEDCOMParser library
5        (developed within the Genealogy Free Software Tools project).
6    
7        The GEDCOMParser library 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 2 of the License, or
10        (at your option) any later version.
11    
12        The GEDCOMParser library 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 the GEDCOMParser library ; if not, write to the Free Software
19        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20    
21    **/
22    
23    #include "GEDCOMParser/DateManagement/DateValue.hh"
24    #include "GEDCOMParser/DateManagement/datevalueparser_decl.hh"
25    
26    #ifdef HAVE_CONFIG_H
27    #include "config.h"
28    #endif // HAVE_CONFIG_H
29    
30    #include "gettext.h"
31    #define _(String) dgettext(PACKAGE, String)
32    
33    
34    GEDCOMParser::DateManagement::DateValue::DateValue(std::string const &value) :
35      _raw_value(),
36      _type(e_Null),
37      _date(0),
38      _date_phrase(0),
39      _period(0),
40      _range(0)
41    {
42      setValue(value);
43      return;
44    }
45    
46    void GEDCOMParser::DateManagement::DateValue::setType(enumDateValueTypes type)
47    {
48      _type = type;
49      return;
50    }
51    
52    void GEDCOMParser::DateManagement::DateValue::setDate(GEDCOMParser::DateManagement::Date const &date)
53    {
54      if ((_date != 0) && (_date != &date))
55        {
56          delete _date; _date = 0;
57        }
58      if (_date != &date)
59        {
60          _date = new GEDCOMParser::DateManagement::Date(date);
61        }
62      return;
63    }
64    
65    void GEDCOMParser::DateManagement::DateValue::setDatePhrase(GEDCOMParser::DateManagement::DatePhrase const &date_phrase)
66    {
67      if ((_date_phrase != 0) && (_date_phrase != &date_phrase))
68        {
69          delete _date_phrase; _date_phrase = 0;
70        }
71      if (_date_phrase != &date_phrase)
72        {
73          _date_phrase = new GEDCOMParser::DateManagement::DatePhrase(date_phrase);
74        }
75      return;
76    }
77    
78    void GEDCOMParser::DateManagement::DateValue::setPeriod(GEDCOMParser::DateManagement::Period const &period)
79    {
80      if ((_period != 0) && (_period != &period))
81        {
82          delete _period; _period = 0;
83        }
84      if (_period != &period)
85        {
86          _period = new GEDCOMParser::DateManagement::Period(period);
87        }
88      return;
89    }
90    
91    void GEDCOMParser::DateManagement::DateValue::setRange(GEDCOMParser::DateManagement::Range const &range)
92    {
93      if ((_range != 0) && (_range != &range))
94        {
95          delete _range; _range = 0;
96        }
97      if (_range != &range)
98        {
99          _range = new GEDCOMParser::DateManagement::Range(range);
100        }
101      return;
102    }
103    
104    void GEDCOMParser::DateManagement::DateValue::setValue(std::string const &value)
105    {
106      _raw_value = value;
107      datevalue_runparse(value, this);
108      return;
109    }
110    
111    void GEDCOMParser::DateManagement::DateValue::setParseError(bool val)
112    {
113      _parsing_ko = val;
114    }
115    
116    std::string const GEDCOMParser::DateManagement::DateValue::getDisplayValue(void) const
117    {
118      std::string res;
119      if (_parsing_ko == true)
120        {
121          res = _raw_value;
122        }
123      else
124        {
125          switch(_type)
126            {
127            case e_Date:
128              if (_date != 0)
129                {
130                  res = _date->getDisplayValue();
131                }
132              break;
133            case e_DatePhrase:
134              if (_date_phrase != 0)
135                {
136                  res = _date_phrase->getDisplayValue();
137                }
138          break;
139            case e_Period:
140          if (_period != 0)
141            {
142              res = _period->getDisplayValue();
143            }
144          break;
145            case e_Range:
146              if (_range != 0)
147                {
148                  res = _range->getDisplayValue();
149                }
150              break;
151            case e_Interpreted:
152              if (_date != 0)
153            {
154              res = _date->getDisplayValue();
155            }
156              if (_date_phrase != 0)
157                {
158                  res = res + _(" interpreted from ") + _date_phrase->getDisplayValue();
159                }
160              break;
161            default:
162              res = _("Unknown date value");
163              res = res + " (" + _raw_value + ")" ;
164              break;
165            }
166        }
167      return res;
168    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26