/////////////////////////////////////////////////////////////////////////////
// Name:        wxbuild.h
// Purpose:     wxWidgetsBuild, wxWidgetsBuildArray - wx builds management
// Author:      Francesco Montorsi
// Modified by:
// Created:     2006-06-29
// RCS-ID:      $Id: wxbuild.h,v 1.1.1.1 2006/12/12 09:41:00 frm Exp $
// Copyright:   (c) Francesco Montorsi
// Licence:     wxWidgets licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WXBUILD_H_
#define _WXBUILD_H_

// Includes
#include "wx/tokenzr.h"
#include "wxp/wxputils.h"
#include "wxp/compiler.h"
#include "wxp/packageopt.h"
#include "wxp/version.h"

// Forward declarations
class wxPackageArray;
class wxPackage;
class wxWidgetsBuildArray;



// ----------------------------------------------------------------------------
// wxWidgetsBuild
// ----------------------------------------------------------------------------

//! Holds information about a wxWidgets build.
class wxWidgetsBuild : public wxObject
{
    DECLARE_DYNAMIC_CLASS(wxWidgetsBuild)

public:
    wxWidgetsBuild()
        { m_format=wxPCF_INVALID; m_port=wxPORT_UNKNOWN;
          m_bStatic=m_bDebug=m_bUnicode=true; }

public:     // getters

    wxString GetLocation() const
        { return m_strLocation; }
    wxVersion GetVersion() const
        { return m_version; }
    wxPortId GetPortId() const
        { return m_port; }

    wxPackageCompilerFormat GetCompilerUsed() const
        { return m_format; }
    bool IsStaticBuild() const
        { return m_bStatic; }
    bool IsDebugBuild() const
        { return m_bDebug; }
    bool IsUnicodeBuild() const
        { return m_bUnicode; }

    wxString GetUserFriendlyName() const;

    static wxArrayString GetSpecialOptionNames();
    void UpdateOptions(wxPackageCommandOptionArray &arr) const;

public:     // setters

    void SetLocation(const wxString &str)
        { m_strLocation=str; }
    void SetVersion(const wxVersion &str)
        { m_version=str; }
    void SetPortId(wxPortId n)
        { m_port=n; }

    void SetCompilerUsed(wxPackageCompilerFormat n)
        { m_format=n; }
     void SetBuildProp(bool staticbuild, bool debug, bool unicode)
        { m_bStatic=staticbuild; m_bDebug=debug; m_bUnicode=unicode; }

public:     // misc

    bool IsOk() const
    {
        return !m_strLocation.IsEmpty() &&
               m_version.IsOk() &&
               m_port != wxPORT_UNKNOWN &&
               m_format != wxPCF_INVALID;
    }

public:     // load/save

    bool Load(wxConfigBase *, const wxString &path);
    void Save(wxConfigBase *, const wxString &path) const;

protected:      // properties of this wxWidgets build

    wxString m_strLocation;
    wxVersion m_version;
    wxPortId m_port;

protected:      // configuration of this build

    wxPackageCompilerFormat m_format;
    bool m_bStatic, m_bDebug, m_bUnicode;
};

// the array
WX_DECLARE_OBJARRAY(wxWidgetsBuild, wxWidgetsBuildArrayHelper);



// ----------------------------------------------------------------------------
// wxWidgetsBuildArray
// ----------------------------------------------------------------------------

class wxWidgetsBuildArray : public wxWidgetsBuildArrayHelper
{
public:

    //! Default constructor does nothing.
    wxWidgetsBuildArray() {}

public:

    static wxWidgetsBuildArray s_arrWxBuilds;

public:     // miscellaneous

    //! Returns true if all options are valid.
    bool IsOk() const
    {
        for (size_t i=0; i<GetCount(); i++)
            if (!Item(i).IsOk())
                return false;
        return true;
    }

    long GetPortList() const
    {
        long ret;
        for (size_t i=0; i<GetCount(); i++)
            ret |= Item(i).GetPortId();
        return ret;
    }

public:     // load/save

    //! Loads the compiler paths from given path.
    static bool LoadGlobals(wxConfigBase *, const wxString &path);

    //! Saves the compiler paths to given path.
    static void SaveGlobals(wxConfigBase *, const wxString &path);
};


#endif      // _WXBUILD_H_

