summary refs log tree commit diff stats
path: root/libs/cocos2d/Support/uthash.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cocos2d/Support/uthash.h')
0 files changed, 0 insertions, 0 deletions
'#n78'>78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
#ifndef TOKEN_H_AD62C505
#define TOKEN_H_AD62C505

#include <string>
#include <list>
#include <sstream>

namespace verbly {
  
  class verb;
  
  class selrestr {
  };
  
  class synrestr {
  };
  
  enum class fillin_type {
    noun_phrase,
    participle_phrase,
    adjective,
    adverb
  };
  
  class token {
    public:
      enum class type {
        verb,
        fillin,
        string,
        utterance
      };
      
    protected:
      // General
      type _type;
      
      token(type _type);
      
    public:
      enum type token_type() const;
      
      virtual bool complete() const = 0;
      virtual std::string compile() const = 0;
      virtual token* copy() const = 0;
  };
  
  class verb_token : public token {
    public:
      enum class inflection {
        infinitive,
        past_tense,
        past_participle,
        ing_form,
        s_form
      };
      
    private:
      // Verb
      const verb* _verb;
      inflection _inflection = inflection::infinitive;
    
    public:
      verb_token(const class verb& _verb);
      
      const class verb& verb() const;
      
      verb_token& inflect(inflection infl);
      
      bool complete() const;
      
      std::string compile() const;
      
      token* copy() const;
  };
  
  class utterance_token : public token {
    private:
      // Utterance
      std::list<std::unique_ptr<token>> utterance;

    public:
      typedef std::list<std::unique_ptr<token>>::iterator iterator;
      /*class iterator {
        private:
          friend class utterance_token;
          
          std::list<std::unique_ptr<token>>::iterator it;
          
        public:
          iterator(std::list<std::unique_ptr<token>>::iterator it) : it(it)
          {
            
          }
          
          iterator& operator++()
          {
            ++it;
            return *this;
          }
          
          iterator& operator--()
          {
            --it;
            return *this;
          }
          
          bool operator==(const iterator& other) const
          {
            return it == other.it;
          }
          
          bool operator!=(const iterator& other) const
          {
            return it != other.it;
          }
          
          token& operator*()
          {
            return **it;
          }
          
          token& operator->()
          {
            return **it;
          }
      };*/
      
      utterance_token(std::initializer_list<token*> tkns) : token(token::type::utterance)
      {
        for (auto tkn : tkns)
        {
          utterance.push_back(std::unique_ptr<token>(tkn));
        }
      }
      
      utterance_token(const utterance_token& other) : token(token::type::utterance)
      {
        for (auto& tkn : other.utterance)
        {
          utterance.push_back(std::unique_ptr<token>(tkn->copy()));
        }
      }
      
      utterance_token(utterance_token&& other) : token(token::type::utterance), utterance(std::move(other.utterance))
      {
        
      }
      
      utterance_token& operator=(const utterance_token& other)
      {
        utterance.clear();
        
        for (auto& tkn : other.utterance)
        {
          utterance.push_back(std::unique_ptr<token>(tkn->copy()));
        }
        
        return *this;
      }
      
      utterance_token& operator=(utterance_token&& other)
      {
        utterance = std::move(other.utterance);
        
        return *this;
      }
      
      iterator begin()
      {
        return std::begin(utterance);
      }
      
      iterator end()
      {
        return std::end(utterance);
      }
      
      void erase(iterator it)
      {
        utterance.erase(it);
      }
      
      bool complete() const
      {
        return std::all_of(std::begin(utterance), std::end(utterance), [] (const std::unique_ptr<token>& tkn) {
          return tkn->complete();
        });
      }
      
      std::string compile() const
      {
        std::stringstream result;
        for (auto& t : utterance)
        {
          if (t->complete())
          {
            result << t->compile() << " ";
          } else {
            return "Could not compile!";
          }
        }
    
        std::string output = result.str();
        if (output != "")
        {
          output.pop_back();
        }
    
        return output;
      }
      
      token* copy() const
      {
        return new utterance_token(*this);
      }
  };
  
  class fillin_token : public token {
    private:    
      // Fillin
      std::string m_theme;
      fillin_type m_fillin_type;
      
    public:
      fillin_token(fillin_type ft) : token(token::type::fillin), m_fillin_type(ft)
      {

      }
      
/*      void synrestrs(std::initializer_list<synrestr> ins)
      {
        m_synrestrs = std::set<synrestr>(ins);
      }
      
      std::set<synrestr>& synrestrs()
      {
        return m_synrestrs;
      }
      
      void selrestrs(std::initializer_list<selrestr> ins)
      {
        m_selrestrs = std::set<selrestr>(ins);
      }
      
      std::set<selrestr>& selrestrs()
      {
        return m_selrestrs;
      }*/
      
      fillin_token theme(std::string theme)
      {
        m_theme = theme;
        
        return *this;
      }
      
      std::string& theme()
      {
        return m_theme;
      }
      
      fillin_type fillin_type() const
      {
        return m_fillin_type;
      }
      
      bool complete() const
      {
        return false;
      }
      
      std::string compile() const
      {
        return "";
      }
      
      token* copy() const
      {
        return new fillin_token(*this);
      }
  };
  
  class string_token : public token {
    private:
      // String
      std::string str;
      
    public:
      string_token(std::string str) : token(token::type::string), str(str)
      {
        
      }
      
      bool complete() const
      {
        return true;
      }
      
      std::string compile() const
      {
        return str;
      }
      
      token* copy() const
      {
        return new string_token(*this);
      }
  };
  
};

#endif /* end of include guard: TOKEN_H_AD62C505 */