diff options
Diffstat (limited to 'generator/part.cpp')
-rw-r--r-- | generator/part.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/generator/part.cpp b/generator/part.cpp index 8a75ed4..07618a8 100644 --- a/generator/part.cpp +++ b/generator/part.cpp | |||
@@ -4,6 +4,8 @@ | |||
4 | namespace verbly { | 4 | namespace verbly { |
5 | namespace generator { | 5 | namespace generator { |
6 | 6 | ||
7 | int part::nextId_ = 0; | ||
8 | |||
7 | part part::createNounPhrase(std::string role, selrestr selrestrs, std::set<std::string> synrestrs) | 9 | part part::createNounPhrase(std::string role, selrestr selrestrs, std::set<std::string> synrestrs) |
8 | { | 10 | { |
9 | part p(type::noun_phrase); | 11 | part p(type::noun_phrase); |
@@ -49,9 +51,52 @@ namespace verbly { | |||
49 | return p; | 51 | return p; |
50 | } | 52 | } |
51 | 53 | ||
54 | part part::duplicate(const part& other) | ||
55 | { | ||
56 | part result(other.type_); | ||
57 | |||
58 | switch (result.type_) | ||
59 | { | ||
60 | case type::noun_phrase: | ||
61 | { | ||
62 | new(&result.noun_phrase_.role) std::string(other.noun_phrase_.role); | ||
63 | new(&result.noun_phrase_.selrestrs) selrestr(other.noun_phrase_.selrestrs); | ||
64 | new(&result.noun_phrase_.synrestrs) std::set<std::string>(other.noun_phrase_.synrestrs); | ||
65 | |||
66 | break; | ||
67 | } | ||
68 | |||
69 | case type::preposition: | ||
70 | { | ||
71 | new(&result.preposition_.choices) std::set<std::string>(other.preposition_.choices); | ||
72 | result.preposition_.literal = other.preposition_.literal; | ||
73 | |||
74 | break; | ||
75 | } | ||
76 | |||
77 | case type::literal: | ||
78 | { | ||
79 | new(&result.literal_) std::string(other.literal_); | ||
80 | |||
81 | break; | ||
82 | } | ||
83 | |||
84 | case type::verb: | ||
85 | case type::adjective: | ||
86 | case type::adverb: | ||
87 | case type::invalid: | ||
88 | { | ||
89 | break; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | return result; | ||
94 | } | ||
95 | |||
52 | part::part(const part& other) | 96 | part::part(const part& other) |
53 | { | 97 | { |
54 | type_ = other.type_; | 98 | type_ = other.type_; |
99 | id_ = other.id_; | ||
55 | 100 | ||
56 | switch (type_) | 101 | switch (type_) |
57 | { | 102 | { |
@@ -106,6 +151,7 @@ namespace verbly { | |||
106 | using type = part::type; | 151 | using type = part::type; |
107 | 152 | ||
108 | type tempType = first.type_; | 153 | type tempType = first.type_; |
154 | int tempId = first.id_; | ||
109 | std::string tempRole; | 155 | std::string tempRole; |
110 | selrestr tempSelrestrs; | 156 | selrestr tempSelrestrs; |
111 | std::set<std::string> tempSynrestrs; | 157 | std::set<std::string> tempSynrestrs; |
@@ -151,6 +197,7 @@ namespace verbly { | |||
151 | first.~part(); | 197 | first.~part(); |
152 | 198 | ||
153 | first.type_ = second.type_; | 199 | first.type_ = second.type_; |
200 | first.id_ = second.id_; | ||
154 | 201 | ||
155 | switch (first.type_) | 202 | switch (first.type_) |
156 | { | 203 | { |
@@ -190,6 +237,7 @@ namespace verbly { | |||
190 | second.~part(); | 237 | second.~part(); |
191 | 238 | ||
192 | second.type_ = tempType; | 239 | second.type_ = tempType; |
240 | second.id_ = tempId; | ||
193 | 241 | ||
194 | switch (second.type_) | 242 | switch (second.type_) |
195 | { | 243 | { |