First commit.
[mverbiste] / verbiste / misc-types.cpp
1 /*  $Id: misc-types.cpp,v 1.10 2010/07/04 05:49:51 sarrazip Exp $
2     misc-types.cpp - Miscellaneous types used by the dictionary class.
3
4     verbiste - French conjugation system
5     Copyright (C) 2003-2010 Pierre Sarrazin <http://sarrazip.com/>
6
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (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, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20     02111-1307, USA.
21 */
22
23 #include <verbiste/misc-types.h>
24 #include <verbiste/FrenchVerbDictionary.h>
25
26 using namespace std;
27 using namespace verbiste;
28
29
30 void
31 ModeTensePersonNumber::set(const char *modeName,
32                                 const char *tenseName,
33                                 int personNum,
34                                 bool isCorrect,
35                                 bool isItalian)
36 {
37     correct = isCorrect;
38     mode = FrenchVerbDictionary::convertModeName(modeName);
39     tense = FrenchVerbDictionary::convertTenseName(tenseName);
40
41     if (mode == IMPERATIVE_MODE)
42     {
43         if (isItalian)
44         {
45             switch (personNum)
46             {
47             case 1: person = 2; plural = false; break;
48             case 2: person = 3; plural = false; break;
49             case 3: person = 1; plural = true; break;
50             case 4: person = 2; plural = true; break;
51             case 5: person = 3; plural = true; break;
52             default: assert(false); person = 0; plural = false;
53             }
54         }
55         else
56         {
57             if (personNum == 1)
58             {
59                 person = 2;
60                 plural = false;
61             }
62             else if (personNum == 2)
63             {
64                 person = 1;
65                 plural = true;
66             }
67             else if (personNum == 3)
68             {
69                 person = 2;
70                 plural = true;
71             }
72             else
73             {
74                 person = 0;
75                 plural = false;
76             }
77         }
78     }
79     else if (mode == INFINITIVE_MODE
80                 || mode == INVALID_MODE
81                 || personNum < 1 || personNum > 6)
82     {
83         person = 0;
84         plural = false;
85     }
86     else if (mode == PARTICIPLE_MODE)
87     {
88         assert(personNum >= 1 && personNum <= 4);
89         person = static_cast<unsigned char>(personNum <= 2 ? 4 : 5);
90                 // convention: 4=masculine, 5=feminine
91         plural = (personNum == 2 || personNum == 4);
92     }
93     else if (mode == GERUND_MODE)
94     {
95         person = 0;
96         plural = false;
97     }
98     else
99     {
100         person = static_cast<unsigned char>((personNum - 1) % 3 + 1);
101         plural = (personNum > 3);
102     }
103 }
104
105
106 void
107 ModeTensePersonNumber::dump(Verbiste_ModeTensePersonNumber &destination) const
108 {
109     destination.mode = (Verbiste_Mode) mode;
110     destination.tense = (Verbiste_Tense) tense;
111     destination.person = (int) person;
112     destination.plural = (int) plural;
113     destination.correct = (int) correct;
114 }