about summary refs log tree commit diff stats
path: root/WitnessRandomizer
ModeNameSize
-rw-r--r--Memory.cpp4252log stats plain blame
-rw-r--r--Memory.h971log stats plain blame
-rw-r--r--WitnessRandomizer.cpp13170log stats plain blame
-rw-r--r--WitnessRandomizer.h470log stats plain blame
-rw-r--r--WitnessRandomizer.vcxproj8438log stats plain blame
-rw-r--r--WitnessRandomizer.vcxproj.filters1430log stats plain blame
-rw-r--r--pch.cpp430log stats plain blame
-rw-r--r--pch.h1262log stats plain blame
*/ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .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 "form.h"
#include <algorithm>
#include <list>
#include "database.h"
#include "field.h"
#include "pronunciation.h"

namespace verbly {
  namespace generator {

    int form::nextId_ = 0;

    form::form(std::string text) :
      id_(nextId_++),
      text_(text),
      complexity_(std::count(std::begin(text), std::end(text), ' ') + 1),
      proper_(std::any_of(std::begin(text), std::end(text), std::isupper))
    {
    }

    void form::addPronunciation(const pronunciation& p)
    {
      pronunciations_.insert(&p);
    }

    database& operator<<(database& db, const form& arg)
    {
      // Serialize the form first.
      {
        std::list<field> fields;
        fields.emplace_back("form_id", arg.getId());
        fields.emplace_back("form", arg.getText());
        fields.emplace_back("complexity", arg.getComplexity());
        fields.emplace_back("proper", arg.isProper());

        db.insertIntoTable("forms", std::move(fields));
      }

      // Then, serialize the form/pronunciation relationship.
      for (const pronunciation* p : arg.getPronunciations())
      {
        std::list<field> fields;
        fields.emplace_back("form_id", arg.getId());
        fields.emplace_back("pronunciation_id", p->getId());

        db.insertIntoTable("forms_pronunciations", std::move(fields));
      }

      return db;
    }

  };
};