// File: danfai[P]dboc/parser.cpp
// Function: Parser::write(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Parser::write(std::string outFile)
{
    if(this->classes.empty()) {
        throw "No classed found";
    }
    std::ofstream out(outFile);
    std::set<std::string> includes;
    std::ostringstream definition;
    std::string headerguard = "DBO_" + this->classes.front().className + "_H";

    includes.insert("#include <Wt/Dbo/Types>");

    out << "#ifndef " << headerguard << std::endl;
    out << "#define " << headerguard << std::endl;
    out << std::endl;
    for(auto &c : this->classes) {
        definition << "class " << c.className << " : public Wt::Dbo::Dbo<" << c.className << ">" << std::endl;
        definition << "{" << std::endl << "  public:" << std::endl;
        // TODO: con-/destructor?
        //definition << "    virtual " << c.className << "();" << std::endl; 
        //definition << "    virtual ~" << c.className << "();" << std::endl; 
        std::ostringstream persist;
        for(auto &f : c.fields) {
            f.getIncludes(includes);
            f.getFieldName(definition);

            switch(f.relation) {
                default:
                    persist << "      Wt::Dbo::field(a, " << f.fieldName << ", \"" << f.databaseName << "\");" << std::endl;
            }
        }
        definition << std::endl;
        definition << "    template<Action>" << std::endl;
        definition << "    void persist(Action &a) {" << std::endl;
        definition << persist.str();
        definition << "    }" << std::endl;
        definition << "}" << std::endl;
        definition << "DBO_EXTERN_TEMPLATES(" << c.className << ");" << std::endl;
    }
    for(auto &s : includes)
        out << s << std::endl;

    out << definition.str() << std::endl;
    out << "#endif // " << headerguard << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x760, %rsp            # imm = 0x760
movq %rsi, -0x668(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x660(%rbp)
callq 0x5730
testb $0x1, %al
jne 0x4be0
jmp 0x4c07
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0x467c(%rip), %rax      # 0x9270
movq %rax, (%rdi)
movq 0x939a(%rip), %rsi      # 0xdf98
xorl %eax, %eax
movl %eax, %edx
callq 0x3390
movq -0x668(%rbp), %rsi
leaq -0x210(%rbp), %rdi
movl $0x10, %edx
callq 0x3420
leaq -0x240(%rbp), %rdi
callq 0x5770
leaq -0x3b8(%rbp), %rdi
callq 0x3300
jmp 0x4c39
movq -0x660(%rbp), %rdi
callq 0x58f0
movq %rax, %rdx
addq $0x8, %rdx
leaq 0x462e(%rip), %rsi      # 0x9281
leaq -0x408(%rbp), %rdi
callq 0x57e0
jmp 0x4c61
leaq 0x461e(%rip), %rdx      # 0x9286
leaq -0x3e8(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x5790
jmp 0x4c7d
leaq -0x408(%rbp), %rdi
callq 0x3180
leaq -0x429(%rbp), %rdi
movq %rdi, -0x670(%rbp)
callq 0x33d0
movq -0x670(%rbp), %rdx
leaq 0x45df(%rip), %rsi      # 0x9289
leaq -0x428(%rbp), %rdi
callq 0x39b0
jmp 0x4cb8
leaq -0x240(%rbp), %rdi
leaq -0x428(%rbp), %rsi
callq 0x5920
movb %dl, -0x679(%rbp)
movq %rax, -0x678(%rbp)
jmp 0x4cda
movb -0x679(%rbp), %al
movq -0x678(%rbp), %rcx
movq %rcx, -0x440(%rbp)
movb %al, -0x438(%rbp)
leaq -0x428(%rbp), %rdi
callq 0x3180
leaq -0x429(%rbp), %rdi
callq 0x3290
leaq 0x458e(%rip), %rsi      # 0x92a1
leaq -0x210(%rbp), %rdi
callq 0x3210
movq %rax, -0x688(%rbp)
jmp 0x4d28
movq -0x688(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x3200
movq %rax, -0x690(%rbp)
jmp 0x4d44
movq -0x690(%rbp), %rdi
movq 0x9236(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x4d59
leaq 0x454a(%rip), %rsi      # 0x92aa
leaq -0x210(%rbp), %rdi
callq 0x3210
movq %rax, -0x698(%rbp)
jmp 0x4d75
movq -0x698(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x3200
movq %rax, -0x6a0(%rbp)
jmp 0x4d91
movq -0x6a0(%rbp), %rdi
movq 0x91e9(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x4da6
movq 0x91db(%rip), %rsi      # 0xdf88
leaq -0x210(%rbp), %rdi
callq 0x3270
jmp 0x4dbb
movq -0x660(%rbp), %rax
movq %rax, -0x448(%rbp)
movq -0x448(%rbp), %rdi
callq 0x5970
movq %rax, -0x450(%rbp)
movq -0x448(%rbp), %rdi
callq 0x59a0
movq %rax, -0x458(%rbp)
leaq -0x450(%rbp), %rdi
leaq -0x458(%rbp), %rsi
callq 0x59d0
testb $0x1, %al
jne 0x4e0b
jmp 0x531c
leaq -0x450(%rbp), %rdi
callq 0x5a10
movq %rax, -0x460(%rbp)
leaq 0x448e(%rip), %rsi      # 0x92b3
leaq -0x3b8(%rbp), %rdi
callq 0x3210
movq %rax, -0x6a8(%rbp)
jmp 0x4e3a
movq -0x6a8(%rbp), %rdi
movq -0x460(%rbp), %rsi
addq $0x8, %rsi
callq 0x3200
movq %rax, -0x6b0(%rbp)
jmp 0x4e5a
movq -0x6b0(%rbp), %rdi
leaq 0x4452(%rip), %rsi      # 0x92ba
callq 0x3210
movq %rax, -0x6b8(%rbp)
jmp 0x4e76
movq -0x6b8(%rbp), %rdi
movq -0x460(%rbp), %rsi
addq $0x8, %rsi
callq 0x3200
movq %rax, -0x6c0(%rbp)
jmp 0x4e96
movq -0x6c0(%rbp), %rdi
leaq 0x4180(%rip), %rsi      # 0x9024
callq 0x3210
movq %rax, -0x6c8(%rbp)
jmp 0x4eb2
movq -0x6c8(%rbp), %rdi
movq 0x90c8(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x4ec7
leaq 0x4460(%rip), %rsi      # 0x932e
leaq -0x3b8(%rbp), %rdi
callq 0x3210
movq %rax, -0x6d0(%rbp)
jmp 0x4ee3
movq -0x6d0(%rbp), %rdi
movq 0x9097(%rip), %rsi      # 0xdf88
callq 0x3270
movq %rax, -0x6d8(%rbp)
jmp 0x4eff
movq -0x6d8(%rbp), %rdi
leaq 0x43c5(%rip), %rsi      # 0x92d2
callq 0x3210
movq %rax, -0x6e0(%rbp)
jmp 0x4f1b
movq -0x6e0(%rbp), %rdi
movq 0x905f(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x4f30
leaq -0x5d8(%rbp), %rdi
callq 0x3300
jmp 0x4f3e
movq -0x460(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x5e0(%rbp)
movq -0x5e0(%rbp), %rdi
callq 0x5a30
movq %rax, -0x5e8(%rbp)
movq -0x5e0(%rbp), %rdi
callq 0x5a60
movq %rax, -0x5f0(%rbp)
leaq -0x5e8(%rbp), %rdi
leaq -0x5f0(%rbp), %rsi
callq 0x5a90
testb $0x1, %al
jne 0x4f92
jmp 0x5154
leaq -0x5e8(%rbp), %rdi
callq 0x5ad0
movq %rax, -0x5f8(%rbp)
movq -0x5f8(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x5af0
jmp 0x4fba
movq -0x5f8(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x5f30
jmp 0x4fcf
jmp 0x5096
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
jmp 0x54cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
jmp 0x54bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
leaq -0x408(%rbp), %rdi
callq 0x3180
jmp 0x54bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
jmp 0x5057
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
leaq -0x428(%rbp), %rdi
callq 0x3180
leaq -0x429(%rbp), %rdi
callq 0x3290
jmp 0x54b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
jmp 0x54b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
jmp 0x530b
leaq 0x423f(%rip), %rsi      # 0x92dc
leaq -0x5d8(%rbp), %rdi
callq 0x3210
movq %rax, -0x6e8(%rbp)
jmp 0x50b2
movq -0x6e8(%rbp), %rdi
movq -0x5f8(%rbp), %rsi
addq $0x30, %rsi
callq 0x3200
movq %rax, -0x6f0(%rbp)
jmp 0x50d2
movq -0x6f0(%rbp), %rdi
leaq 0x4215(%rip), %rsi      # 0x92f5
callq 0x3210
movq %rax, -0x6f8(%rbp)
jmp 0x50ee
movq -0x6f8(%rbp), %rdi
movq -0x5f8(%rbp), %rsi
addq $0x50, %rsi
callq 0x3200
movq %rax, -0x700(%rbp)
jmp 0x510e
movq -0x700(%rbp), %rdi
leaq 0x41dd(%rip), %rsi      # 0x92f9
callq 0x3210
movq %rax, -0x708(%rbp)
jmp 0x512a
movq -0x708(%rbp), %rdi
movq 0x8e50(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x513f
jmp 0x5141
jmp 0x5143
leaq -0x5e8(%rbp), %rdi
callq 0x60b0
jmp 0x4f76
movq 0x8e2d(%rip), %rsi      # 0xdf88
leaq -0x3b8(%rbp), %rdi
callq 0x3270
jmp 0x5169
leaq 0x418d(%rip), %rsi      # 0x92fd
leaq -0x3b8(%rbp), %rdi
callq 0x3210
movq %rax, -0x710(%rbp)
jmp 0x5185
movq -0x710(%rbp), %rdi
movq 0x8df5(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x519a
leaq 0x4171(%rip), %rsi      # 0x9312
leaq -0x3b8(%rbp), %rdi
callq 0x3210
movq %rax, -0x718(%rbp)
jmp 0x51b6
movq -0x718(%rbp), %rdi
movq 0x8dc4(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x51cb
leaq -0x618(%rbp), %rdi
leaq -0x5d8(%rbp), %rsi
callq 0x3240
jmp 0x51e0
leaq -0x3b8(%rbp), %rdi
leaq -0x618(%rbp), %rsi
callq 0x3200
jmp 0x51f5
leaq -0x618(%rbp), %rdi
callq 0x3180
leaq 0x4128(%rip), %rsi      # 0x9330
leaq -0x3b8(%rbp), %rdi
callq 0x3210
movq %rax, -0x720(%rbp)
jmp 0x521d
movq -0x720(%rbp), %rdi
movq 0x8d5d(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x5232
leaq 0x40fb(%rip), %rsi      # 0x9334
leaq -0x3b8(%rbp), %rdi
callq 0x3210
movq %rax, -0x728(%rbp)
jmp 0x524e
movq -0x728(%rbp), %rdi
movq 0x8d2c(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x5263
leaq 0x40cc(%rip), %rsi      # 0x9336
leaq -0x3b8(%rbp), %rdi
callq 0x3210
movq %rax, -0x730(%rbp)
jmp 0x527f
movq -0x730(%rbp), %rdi
movq -0x460(%rbp), %rsi
addq $0x8, %rsi
callq 0x3200
movq %rax, -0x738(%rbp)
jmp 0x529f
movq -0x738(%rbp), %rdi
leaq 0x404d(%rip), %rsi      # 0x92fa
callq 0x3210
movq %rax, -0x740(%rbp)
jmp 0x52bb
movq -0x740(%rbp), %rdi
movq 0x8cbf(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x52d0
leaq -0x5d8(%rbp), %rdi
callq 0x3090
leaq -0x450(%rbp), %rdi
callq 0x60d0
jmp 0x4def
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
leaq -0x618(%rbp), %rdi
callq 0x3180
leaq -0x5d8(%rbp), %rdi
callq 0x3090
jmp 0x54b3
leaq -0x240(%rbp), %rax
movq %rax, -0x620(%rbp)
movq -0x620(%rbp), %rdi
callq 0x60f0
movq %rax, -0x628(%rbp)
movq -0x620(%rbp), %rdi
callq 0x6120
movq %rax, -0x630(%rbp)
leaq -0x628(%rbp), %rdi
leaq -0x630(%rbp), %rsi
callq 0x6150
testb $0x1, %al
jne 0x5369
jmp 0x53bd
leaq -0x628(%rbp), %rdi
callq 0x6180
movq %rax, -0x638(%rbp)
movq -0x638(%rbp), %rsi
leaq -0x210(%rbp), %rdi
callq 0x3200
movq %rax, -0x748(%rbp)
jmp 0x5398
movq -0x748(%rbp), %rdi
movq 0x8be2(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x53ad
jmp 0x53af
leaq -0x628(%rbp), %rdi
callq 0x61a0
jmp 0x5350
leaq -0x658(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0x3240
jmp 0x53d2
leaq -0x210(%rbp), %rdi
leaq -0x658(%rbp), %rsi
callq 0x3200
movq %rax, -0x750(%rbp)
jmp 0x53ee
movq -0x750(%rbp), %rdi
movq 0x8b8c(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x5403
leaq -0x658(%rbp), %rdi
callq 0x3180
leaq 0x3f36(%rip), %rsi      # 0x934c
leaq -0x210(%rbp), %rdi
callq 0x3210
movq %rax, -0x758(%rbp)
jmp 0x542b
movq -0x758(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x3200
movq %rax, -0x760(%rbp)
jmp 0x5447
movq -0x760(%rbp), %rdi
movq 0x8b33(%rip), %rsi      # 0xdf88
callq 0x3270
jmp 0x545c
leaq -0x3e8(%rbp), %rdi
callq 0x3180
leaq -0x3b8(%rbp), %rdi
callq 0x3090
leaq -0x240(%rbp), %rdi
callq 0x61d0
leaq -0x210(%rbp), %rdi
callq 0x3340
addq $0x760, %rsp            # imm = 0x760
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x3c0(%rbp)
movl %eax, -0x3c4(%rbp)
leaq -0x658(%rbp), %rdi
callq 0x3180
leaq -0x3e8(%rbp), %rdi
callq 0x3180
leaq -0x3b8(%rbp), %rdi
callq 0x3090
leaq -0x240(%rbp), %rdi
callq 0x61d0
leaq -0x210(%rbp), %rdi
callq 0x3340
movq -0x3c0(%rbp), %rdi
callq 0x33b0
nop