/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2010 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstd
 * Version: 1.07
 * First release date:   2010-11-08
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstd library
 * 
 * mzstd library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstd library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#include "mzObject.h"



VOID WINAPI swap(CObject** object1, CObject** object2) {
    CObject* tmp = *object1;
    *object1 = *object2;
    *object2 = tmp;
}





CObject::CObject() {
    this->_commonInit();
}

CObject::CObject(const CObject& object) {
    this->_commonInit();
    this->setRealClassName(object._realClassName);
}

VOID WINAPI CObject::_commonInit() {
    static LONGLONG id = 0;
    
    id += 1;
    
    DWORD bufsize = wcslen(::cobjectClassName) + 1;
    this->_originClassName = new WCHAR[bufsize];
    if (this->_originClassName) {
        wcscpy_s(this->_originClassName, bufsize, ::cobjectClassName);
    }
    
    this->_realClassName = new WCHAR[64];
    this->setRealClassName(::cobjectClassName);

    this->_objectId = id;
}


CObject::~CObject() {
    if (this->_originClassName) {
        delete[] this->_originClassName;
    }
    if (this->_realClassName) {
        delete[] this->_realClassName;
    }
}


BOOL CObject::equals(CObject* obj) {
    return this == obj;
}

CString CObject::toString() {
    return CString(L"CObject [id: ") + this->_objectId + L"]; originClassName: " + this->_originClassName + L"; realClassName: " + this->_realClassName;
}

CObject::operator WCHAR*() {
    static CString s;
    s = this->toString();
    return s.getBuffer();
}

VOID CObject::setRealClassName(WCHAR* realClassName) {
    if (this->_realClassName) {
        wcscpy_s(this->_realClassName, 64, realClassName);
    }
}
