food_chain: variables are renamed

This commit is contained in:
Dmitry Kokorin 2016-02-29 23:53:09 +03:00
parent c80a6294e1
commit 83939d8584

View file

@ -1,12 +1,10 @@
#include "food_chain.h" #include "food_chain.h"
#include <string>
namespace food_chain { namespace food_chain {
using namespace std; using namespace std;
#define ANIMAL_TABLE \ #define VERSE_TABLE \
X(Fly, "fly", "") \ X(Fly, "fly", "") \
X(Spider, "spider", "It wriggled and jiggled and tickled inside her.\n") \ X(Spider, "spider", "It wriggled and jiggled and tickled inside her.\n") \
X(Bird, "bird", "How absurd to swallow a bird!\n") \ X(Bird, "bird", "How absurd to swallow a bird!\n") \
@ -17,20 +15,20 @@ X(Cow, "cow", "I don't know how she swallowed a cow!\n") \
X(Horse, "horse", "She's dead, of course!\n") X(Horse, "horse", "She's dead, of course!\n")
#define X(a, b, c) a, #define X(a, b, c) a,
enum Animal { enum Verse {
ANIMAL_TABLE VERSE_TABLE
}; };
#undef X #undef X
#define X(a, b, c) b, #define X(a, b, c) b,
static const char *animal_name[] = { static const char *food_name[] = {
ANIMAL_TABLE VERSE_TABLE
}; };
#undef X #undef X
#define X(a, b, c) c, #define X(a, b, c) c,
static const char *verse_phrase[] = { static const char *verse_phrase[] = {
ANIMAL_TABLE VERSE_TABLE
}; };
#undef X #undef X
@ -42,20 +40,20 @@ string verse(int index)
--index; --index;
result += string("I know an old lady who swallowed a ") result += string("I know an old lady who swallowed a ")
+ animal_name[index] + food_name[index]
+ ".\n" + ".\n"
+ verse_phrase[index]; + verse_phrase[index];
if (index != Animal::Horse) { if (index != Verse::Horse) {
for (int i = index; i > Animal::Fly; --i) { for (int i = index; i > Verse::Fly; --i) {
result += string("She swallowed the ") result += string("She swallowed the ")
+ animal_name[i] + food_name[i]
+ " to catch the " + " to catch the "
+ animal_name[i-1]; + food_name[i-1];
if (i == Animal::Bird) if (i == Verse::Bird)
result += string(" that wriggled and jiggled and " result += string(" that wriggled and jiggled and "
"tickled inside her"); "tickled inside her");