Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.0 kB
7
Indexable
#pragma once

#include "identity_document.h"
#include <iostream>
#include <string>
#include <ctime>

using namespace std::string_view_literals;

class Passport {
public:
    operator IdentityDocument() 
    {
        return IdentityDocument();
    }
    Passport()
        : expiration_date_(GetExpirationDate()) 
    {
            ((IdentityDocument*)this)->vMethod = (void (IdentityDocument::*)()const)&Passport::PrintID;
            ((IdentityDocument*)this)->vdel = (void (IdentityDocument::*)())&Passport::Delete;
        std::cout << "Passport::Ctor()"sv << std::endl;
    }

    Passport(const Passport& other)
        : expiration_date_(other.expiration_date_) 
    {
            IdentityDocument id(reinterpret_cast<const IdentityDocument&>(other));
        ((IdentityDocument*)this)->vMethod = (void (IdentityDocument::*)()const)&Passport::PrintID;
            ((IdentityDocument*)this)->vdel = (void (IdentityDocument::*)())&Passport::Delete;
        std::cout << "Passport::CCtor()"sv << std::endl;
    }

    ~Passport() {
        std::cout << "Passport::Dtor()"sv << std::endl;
    }

    void PrintID() const {
        std::cout << "Passport::PrintID() : "sv << ((IdentityDocument*)this)->GetID();
        std::cout << " expiration date : "sv << expiration_date_.tm_mday << "/"sv << expiration_date_.tm_mon << "/"sv
                  << expiration_date_.tm_year + 1900 << std::endl;
    }

    void PrintVisa(const std::string& country) const {
        std::cout << "Passport::PrintVisa("sv << country << ") : "sv << ((IdentityDocument*)this)->GetID() << std::endl;
    }
    
    void PrintUniqueIDCount() {
        ((IdentityDocument*)this)->PrintUniqueIDCount();
    }
    
    void Delete()
    {
        delete this;
    }

private:
    const struct tm expiration_date_;

    tm GetExpirationDate() {
	    time_t t = time(nullptr);
	    tm exp_date = *localtime(&t);
	    exp_date.tm_year += 10;
	    mktime(&exp_date);
	    return exp_date;
	}
};