about summary refs log tree commit diff stats
path: root/data/maps/the_partial/rooms/P Room.txtpb
blob: 618ebd974853410be290cb00244e286d1254de6e (plain) (blame)
1
2
3
4
5
name: "P Room"
letters {
  key: "p"
  path: "Components/Collectables/collectable"
}
/ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "lemma.h"
#include <sqlite3.h>
#include "database.h"
#include "query.h"

namespace verbly {
  
  const object lemma::objectType = object::lemma;
  
  const std::list<std::string> lemma::select = {"lemma_id"};
  
  const field lemma::id = field::integerField(object::lemma, "lemma_id");
  
  const field lemma::word = field::joinField(object::lemma, "lemma_id", object::word);
  
  const field lemma::formJoin = field::joinField(object::lemma, "form_id", object::form);
  const field lemma::inflectionCategory = field::integerField(object::lemma, "category");
  
  filter operator%=(lemma::inflection_field check, filter joinCondition)
  {
    return (lemma::formJoin %= joinCondition) && (lemma::inflectionCategory == check.getCategory());
  }
  
  lemma::lemma(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true)
  {
    id_ = sqlite3_column_int(row, 0);
  }
  
  const form& lemma::getBaseForm() const
  {
    if (!valid_)
    {
      throw std::domain_error("Bad access to uninitialized lemma");
    }
    
    if (!forms_.count(inflection::base))
    {
      initializeForm(inflection::base);
    }
    
    return forms_.at(inflection::base).front();
  }
  
  bool lemma::hasInflection(inflection category) const
  {
    return !getInflections(category).empty();
  }
  
  const std::vector<form>& lemma::getInflections(inflection category) const
  {
    if (!valid_)
    {
      throw std::domain_error("Bad access to uninitialized lemma");
    }
    
    if (!forms_.count(category))
    {
      initializeForm(category);
    }
    
    return forms_.at(category);
  }
  
  void lemma::initializeForm(inflection infl) const
  {
    forms_[infl] = db_->forms(form::lemma(infl) %= *this, false, -1).all();
  }
  
};