This file is indexed.

/usr/include/wx-3.0/wx/any.h is in wx3.0-headers 3.0.4+dfsg-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/any.h
// Purpose:     wxAny class
// Author:      Jaakko Salli
// Modified by:
// Created:     07/05/2009
// Copyright:   (c) wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_ANY_H_
#define _WX_ANY_H_

#include "wx/defs.h"

#if wxUSE_ANY

#include <new> // for placement new
#include "wx/string.h"
#include "wx/meta/if.h"
#include "wx/typeinfo.h"
#include "wx/list.h"

// Size of the wxAny value buffer.
enum
{
    WX_ANY_VALUE_BUFFER_SIZE = 16
};

union wxAnyValueBuffer
{
    union Alignment
    {
    #if wxHAS_INT64
        wxInt64 m_int64;
    #endif
        long double m_longDouble;
        void ( *m_funcPtr )(void);
        void ( wxAnyValueBuffer::*m_mFuncPtr )(void);
    } m_alignment;

    void*   m_ptr;
    wxByte  m_buffer[WX_ANY_VALUE_BUFFER_SIZE];
};

//
// wxAnyValueType is base class for value type functionality for C++ data
// types used with wxAny. Usually the default template (wxAnyValueTypeImpl<>)
// will create a satisfactory wxAnyValueType implementation for a data type.
//
class WXDLLIMPEXP_BASE wxAnyValueType
{
    WX_DECLARE_ABSTRACT_TYPEINFO(wxAnyValueType)
public:
    /**
        Default constructor.
    */
    wxAnyValueType()
    {
    }

    /**
        Destructor.
    */
    virtual ~wxAnyValueType()
    {
    }

    /**
        This function is used for internal type matching.
    */
    virtual bool IsSameType(const wxAnyValueType* otherType) const = 0;

    /**
        This function is called every time the data in wxAny
        buffer needs to be freed.
    */
    virtual void DeleteValue(wxAnyValueBuffer& buf) const = 0;

    /**
        Implement this for buffer-to-buffer copy.

        @param src
            This is the source data buffer.

        @param dst
            This is the destination data buffer that is in either
            uninitialized or freed state.
    */
    virtual void CopyBuffer(const wxAnyValueBuffer& src,
                            wxAnyValueBuffer& dst) const = 0;

    /**
        Convert value into buffer of different type. Return false if
        not possible.
    */
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
                              wxAnyValueType* dstType,
                              wxAnyValueBuffer& dst) const = 0;

    /**
        Use this template function for checking if wxAnyValueType represents
        a specific C++ data type.

        @remarks This template function does not work on some older compilers
                (such as Visual C++ 6.0). For full compiler compatibility
                please use wxANY_VALUE_TYPE_CHECK_TYPE(valueTypePtr, T) macro
                instead.

        @see wxAny::CheckType()
    */
    // FIXME-VC6: remove this hack when VC6 is no longer supported
    template <typename T>
    bool CheckType(T* reserved = NULL) const;

#if wxUSE_EXTENDED_RTTI
    virtual const wxTypeInfo* GetTypeInfo() const = 0;
#endif
private:
};


//
// We need to allocate wxAnyValueType instances in heap, and need to use
// scoped ptr to properly deallocate them in dynamic library use cases.
// Here we have a minimal specialized scoped ptr implementation to deal
// with various compiler-specific problems with template class' static
// member variable of template type with explicit constructor which
// is initialized in global scope.
//
class wxAnyValueTypeScopedPtr
{
public:
    wxAnyValueTypeScopedPtr(wxAnyValueType* ptr) : m_ptr(ptr) { }
    ~wxAnyValueTypeScopedPtr() { delete m_ptr; }
    wxAnyValueType* get() const { return m_ptr; }
private:
    wxAnyValueType* m_ptr;
};


//
// This method of checking the type is compatible with VC6
#define wxANY_VALUE_TYPE_CHECK_TYPE(valueTypePtr, T) \
    wxAnyValueTypeImpl<T>::IsSameClass(valueTypePtr)


/**
    Helper macro for defining user value types.

    Even though C++ RTTI would be fully available to use, we'd have to to
    facilitate sub-type system which allows, for instance, wxAny with
    signed short '15' to be treated equal to wxAny with signed long long '15'.
    Having sm_instance is important here.

    NB: We really need to have wxAnyValueType instances allocated
        in heap. They are stored as static template member variables,
        and with them we just can't be too careful (eg. not allocating
        them in heap broke the type identification in GCC).
*/
#define WX_DECLARE_ANY_VALUE_TYPE(CLS) \
    friend class wxAny; \
    WX_DECLARE_TYPEINFO_INLINE(CLS) \
public: \
    static bool IsSameClass(const wxAnyValueType* otherType) \
    { \
        return AreSameClasses(*sm_instance.get(), *otherType); \
    } \
    virtual bool IsSameType(const wxAnyValueType* otherType) const \
    { \
        return IsSameClass(otherType); \
    } \
private: \
    static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b) \
    { \
        return wxTypeId(a) == wxTypeId(b); \
    } \
    static wxAnyValueTypeScopedPtr sm_instance; \
public: \
    static wxAnyValueType* GetInstance() \
    { \
        return sm_instance.get(); \
    }


#define WX_IMPLEMENT_ANY_VALUE_TYPE(CLS) \
wxAnyValueTypeScopedPtr CLS::sm_instance(new CLS());


#ifdef __VISUALC6__
    // "non dll-interface class 'xxx' used as base interface
    #pragma warning (push)
    #pragma warning (disable:4275)
#endif

/**
    Following are helper classes for the wxAnyValueTypeImplBase.
*/
namespace wxPrivate
{

template<typename T>
class wxAnyValueTypeOpsInplace
{
public:
    static void DeleteValue(wxAnyValueBuffer& buf)
    {
        T* value = reinterpret_cast<T*>(&buf.m_buffer[0]);
        value->~T();

        // Some compiler may given 'unused variable' warnings without this
        wxUnusedVar(value);
    }

    static void SetValue(const T& value,
                         wxAnyValueBuffer& buf)
    {
        // Use placement new
        void* const place = buf.m_buffer;
        ::new(place) T(value);
    }

    static const T& GetValue(const wxAnyValueBuffer& buf)
    {
        // Breaking this code into two lines should suppress
        // GCC's 'type-punned pointer will break strict-aliasing rules'
        // warning.
        const T* value = reinterpret_cast<const T*>(&buf.m_buffer[0]);
        return *value;
    }
};


template<typename T>
class wxAnyValueTypeOpsGeneric
{
public:
    template<typename T2>
    class DataHolder
    {
    public:
        DataHolder(const T2& value)
        {
            m_value = value;
        }
        virtual ~DataHolder() { }

        T2   m_value;
    private:
        wxDECLARE_NO_COPY_CLASS(DataHolder);
    };

    static void DeleteValue(wxAnyValueBuffer& buf)
    {
        DataHolder<T>* holder = static_cast<DataHolder<T>*>(buf.m_ptr);
        delete holder;
    }

    static void SetValue(const T& value,
                         wxAnyValueBuffer& buf)
    {
        DataHolder<T>* holder = new DataHolder<T>(value);
        buf.m_ptr = holder;
    }

    static const T& GetValue(const wxAnyValueBuffer& buf)
    {
        DataHolder<T>* holder = static_cast<DataHolder<T>*>(buf.m_ptr);
        return holder->m_value;
    }
};

} // namespace wxPrivate


/**
    Intermediate template for the generic value type implementation.
    We can derive from this same value type for multiple actual types
    (for instance, we can have wxAnyValueTypeImplInt for all signed
    integer types), and also easily implement specialized templates
    with specific dynamic type conversion.
*/
template<typename T>
class wxAnyValueTypeImplBase : public wxAnyValueType
{
    typedef typename wxIf< sizeof(T) <= WX_ANY_VALUE_BUFFER_SIZE,
                           wxPrivate::wxAnyValueTypeOpsInplace<T>,
                           wxPrivate::wxAnyValueTypeOpsGeneric<T> >::value
            Ops;

public:
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
    virtual ~wxAnyValueTypeImplBase() { }

    virtual void DeleteValue(wxAnyValueBuffer& buf) const
    {
        Ops::DeleteValue(buf);
    }

    virtual void CopyBuffer(const wxAnyValueBuffer& src,
                            wxAnyValueBuffer& dst) const
    {
        Ops::SetValue(Ops::GetValue(src), dst);
    }

    /**
        It is important to reimplement this in any specialized template
        classes that inherit from wxAnyValueTypeImplBase.
    */
    static void SetValue(const T& value,
                         wxAnyValueBuffer& buf)
    {
        Ops::SetValue(value, buf);
    }

    /**
        It is important to reimplement this in any specialized template
        classes that inherit from wxAnyValueTypeImplBase.
    */
    static const T& GetValue(const wxAnyValueBuffer& buf)
    {
        return Ops::GetValue(buf);
    }
#if wxUSE_EXTENDED_RTTI
    virtual const wxTypeInfo* GetTypeInfo() const 
    {
        return wxGetTypeInfo((T*)NULL);
    }
#endif
};


/*
    Generic value type template. Note that bulk of the implementation
    resides in wxAnyValueTypeImplBase.
*/
template<typename T>
class wxAnyValueTypeImpl : public wxAnyValueTypeImplBase<T>
{
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<T>)
public:
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
    virtual ~wxAnyValueTypeImpl() { }

    virtual bool ConvertValue(const wxAnyValueBuffer& src,
                              wxAnyValueType* dstType,
                              wxAnyValueBuffer& dst) const
    {
        wxUnusedVar(src);
        wxUnusedVar(dstType);
        wxUnusedVar(dst);
        return false;
    }
};

template<typename T>
wxAnyValueTypeScopedPtr wxAnyValueTypeImpl<T>::sm_instance = new wxAnyValueTypeImpl<T>();


//
// Helper macro for using same base value type implementation for multiple
// actual C++ data types.
//
#define _WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \
template<> \
class wxAnyValueTypeImpl<T> : public wxAnyValueTypeImpl##CLSTYPE \
{ \
    typedef wxAnyBase##CLSTYPE##Type UseDataType; \
public: \
    wxAnyValueTypeImpl() : wxAnyValueTypeImpl##CLSTYPE() { } \
    virtual ~wxAnyValueTypeImpl() { } \
    static void SetValue(const T& value, wxAnyValueBuffer& buf) \
    { \
        void* voidPtr = reinterpret_cast<void*>(&buf.m_buffer[0]); \
        UseDataType* dptr = reinterpret_cast<UseDataType*>(voidPtr); \
        *dptr = static_cast<UseDataType>(value); \
    } \
    static T GetValue(const wxAnyValueBuffer& buf) \
    { \
        const void* voidPtr = \
            reinterpret_cast<const void*>(&buf.m_buffer[0]); \
        const UseDataType* sptr = \
            reinterpret_cast<const UseDataType*>(voidPtr); \
        return static_cast<T>(*sptr); \
    } 

#if wxUSE_EXTENDED_RTTI
#define WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \
_WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE)\
    virtual const wxTypeInfo* GetTypeInfo() const  \
    { \
        return wxGetTypeInfo((T*)NULL); \
    } \
};
#else
#define WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \
_WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE)\
};
#endif

//
//  Integer value types
//

#ifdef wxLongLong_t
    typedef wxLongLong_t wxAnyBaseIntType;
    typedef wxULongLong_t wxAnyBaseUintType;
#else
    typedef long wxAnyBaseIntType;
    typedef unsigned long wxAnyBaseUintType;
#endif


class WXDLLIMPEXP_BASE wxAnyValueTypeImplInt :
    public wxAnyValueTypeImplBase<wxAnyBaseIntType>
{
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplInt)
public:
    wxAnyValueTypeImplInt() :
        wxAnyValueTypeImplBase<wxAnyBaseIntType>() { }
    virtual ~wxAnyValueTypeImplInt() { }

    virtual bool ConvertValue(const wxAnyValueBuffer& src,
                              wxAnyValueType* dstType,
                              wxAnyValueBuffer& dst) const;
};


class WXDLLIMPEXP_BASE wxAnyValueTypeImplUint :
    public wxAnyValueTypeImplBase<wxAnyBaseUintType>
{
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplUint)
public:
    wxAnyValueTypeImplUint() :
        wxAnyValueTypeImplBase<wxAnyBaseUintType>() { }
    virtual ~wxAnyValueTypeImplUint() { }

    virtual bool ConvertValue(const wxAnyValueBuffer& src,
                              wxAnyValueType* dstType,
                              wxAnyValueBuffer& dst) const;
};


WX_ANY_DEFINE_SUB_TYPE(signed long, Int)
WX_ANY_DEFINE_SUB_TYPE(signed int, Int)
WX_ANY_DEFINE_SUB_TYPE(signed short, Int)
WX_ANY_DEFINE_SUB_TYPE(signed char, Int)
#ifdef wxLongLong_t
WX_ANY_DEFINE_SUB_TYPE(wxLongLong_t, Int)
#endif

WX_ANY_DEFINE_SUB_TYPE(unsigned long, Uint)
WX_ANY_DEFINE_SUB_TYPE(unsigned int, Uint)
WX_ANY_DEFINE_SUB_TYPE(unsigned short, Uint)
WX_ANY_DEFINE_SUB_TYPE(unsigned char, Uint)
#ifdef wxLongLong_t
WX_ANY_DEFINE_SUB_TYPE(wxULongLong_t, Uint)
#endif


//
// This macro is used in header, but then in source file we must have:
// WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl##TYPENAME)
//
#define _WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, CONVFUNC, GV) \
class WXDLLIMPEXP_BASE wxAnyValueTypeImpl##TYPENAME : \
    public wxAnyValueTypeImplBase<T> \
{ \
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl##TYPENAME) \
public: \
    wxAnyValueTypeImpl##TYPENAME() : \
        wxAnyValueTypeImplBase<T>() { } \
    virtual ~wxAnyValueTypeImpl##TYPENAME() { } \
    virtual bool ConvertValue(const wxAnyValueBuffer& src, \
                              wxAnyValueType* dstType, \
                              wxAnyValueBuffer& dst) const \
    { \
        GV value = GetValue(src); \
        return CONVFUNC(value, dstType, dst); \
    } \
}; \
template<> \
class wxAnyValueTypeImpl<T> : public wxAnyValueTypeImpl##TYPENAME \
{ \
public: \
    wxAnyValueTypeImpl() : wxAnyValueTypeImpl##TYPENAME() { } \
    virtual ~wxAnyValueTypeImpl() { } \
};

#define WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, CONVFUNC, BT) \
_WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, CONVFUNC, BT) \

#define WX_ANY_DEFINE_CONVERTIBLE_TYPE_BASE(T, TYPENAME, CONVFUNC) \
_WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, \
                                CONVFUNC, const T&) \

//
// String value type
//

// Convert wxString to destination wxAny value type
extern WXDLLIMPEXP_BASE bool wxAnyConvertString(const wxString& value,
                                                wxAnyValueType* dstType,
                                                wxAnyValueBuffer& dst);

WX_ANY_DEFINE_CONVERTIBLE_TYPE_BASE(wxString, wxString, wxAnyConvertString)
WX_ANY_DEFINE_CONVERTIBLE_TYPE(const char*, ConstCharPtr,
                               wxAnyConvertString, wxString)
WX_ANY_DEFINE_CONVERTIBLE_TYPE(const wchar_t*, ConstWchar_tPtr,
                               wxAnyConvertString, wxString)

//
// Bool value type
//
template<>
class WXDLLIMPEXP_BASE wxAnyValueTypeImpl<bool> :
    public wxAnyValueTypeImplBase<bool>
{
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<bool>)
public:
    wxAnyValueTypeImpl() :
        wxAnyValueTypeImplBase<bool>() { }
    virtual ~wxAnyValueTypeImpl() { }

    virtual bool ConvertValue(const wxAnyValueBuffer& src,
                              wxAnyValueType* dstType,
                              wxAnyValueBuffer& dst) const;
};

//
// Floating point value type
//
class WXDLLIMPEXP_BASE wxAnyValueTypeImplDouble :
    public wxAnyValueTypeImplBase<double>
{
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplDouble)
public:
    wxAnyValueTypeImplDouble() :
        wxAnyValueTypeImplBase<double>() { }
    virtual ~wxAnyValueTypeImplDouble() { }

    virtual bool ConvertValue(const wxAnyValueBuffer& src,
                              wxAnyValueType* dstType,
                              wxAnyValueBuffer& dst) const;
};

// WX_ANY_DEFINE_SUB_TYPE requires this
typedef double wxAnyBaseDoubleType;

WX_ANY_DEFINE_SUB_TYPE(float, Double)
WX_ANY_DEFINE_SUB_TYPE(double, Double)


//
// Defines a dummy wxAnyValueTypeImpl<> with given export
// declaration. This is needed if a class is used with
// wxAny in both user shared library and application.
//
#define wxDECLARE_ANY_TYPE(CLS, DECL) \
template<> \
class DECL wxAnyValueTypeImpl<CLS> : \
    public wxAnyValueTypeImplBase<CLS> \
{ \
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<CLS>) \
public: \
    wxAnyValueTypeImpl() : \
        wxAnyValueTypeImplBase<CLS>() { } \
    virtual ~wxAnyValueTypeImpl() { } \
 \
    virtual bool ConvertValue(const wxAnyValueBuffer& src, \
                              wxAnyValueType* dstType, \
                              wxAnyValueBuffer& dst) const \
    { \
        wxUnusedVar(src); \
        wxUnusedVar(dstType); \
        wxUnusedVar(dst); \
        return false; \
    } \
};


// Make sure some of wx's own types get the right wxAnyValueType export
// (this is needed only for types that are referred to from wxBase.
// currently we may not use any of these types from there, but let's
// use the macro on at least one to make sure it compiles since we can't
// really test it properly in unit tests since a separate DLL would
// be needed).
#if wxUSE_DATETIME
    #include "wx/datetime.h"
    wxDECLARE_ANY_TYPE(wxDateTime, WXDLLIMPEXP_BASE)
#endif

//#include "wx/object.h"
//wxDECLARE_ANY_TYPE(wxObject*, WXDLLIMPEXP_BASE)

//#include "wx/arrstr.h"
//wxDECLARE_ANY_TYPE(wxArrayString, WXDLLIMPEXP_BASE)


#if wxUSE_VARIANT

class WXDLLIMPEXP_FWD_BASE wxAnyToVariantRegistration;

// Because of header inter-dependencies, cannot include this earlier
#include "wx/variant.h"

//
// wxVariantData* data type implementation. For cases when appropriate
// wxAny<->wxVariant conversion code is missing.
//

class WXDLLIMPEXP_BASE wxAnyValueTypeImplVariantData :
    public wxAnyValueTypeImplBase<wxVariantData*>
{
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplVariantData)
public:
    wxAnyValueTypeImplVariantData() :
        wxAnyValueTypeImplBase<wxVariantData*>() { }
    virtual ~wxAnyValueTypeImplVariantData() { }

    virtual void DeleteValue(wxAnyValueBuffer& buf) const
    {
        wxVariantData* data = static_cast<wxVariantData*>(buf.m_ptr);
        if ( data )
            data->DecRef();
    }

    virtual void CopyBuffer(const wxAnyValueBuffer& src,
                            wxAnyValueBuffer& dst) const
    {
        wxVariantData* data = static_cast<wxVariantData*>(src.m_ptr);
        if ( data )
            data->IncRef();
        dst.m_ptr = data;
    }

    static void SetValue(wxVariantData* value,
                         wxAnyValueBuffer& buf)
    {
        value->IncRef();
        buf.m_ptr = value;
    }

    static wxVariantData* GetValue(const wxAnyValueBuffer& buf)
    {
        return static_cast<wxVariantData*>(buf.m_ptr);
    }

    virtual bool ConvertValue(const wxAnyValueBuffer& src,
                              wxAnyValueType* dstType,
                              wxAnyValueBuffer& dst) const
    {
        wxUnusedVar(src);
        wxUnusedVar(dstType);
        wxUnusedVar(dst);
        return false;
    }
};

template<>
class wxAnyValueTypeImpl<wxVariantData*> :
    public wxAnyValueTypeImplVariantData
{
public:
    wxAnyValueTypeImpl() : wxAnyValueTypeImplVariantData() { }
    virtual ~wxAnyValueTypeImpl() { }
};

#endif // wxUSE_VARIANT

#ifdef __VISUALC6__
    // Re-enable useless VC6 warnings
    #pragma warning (pop)
#endif


/*
    Let's define a discrete Null value so we don't have to really
    ever check if wxAny.m_type pointer is NULL or not. This is an
    optimization, mostly. Implementation of this value type is
    "hidden" in the source file.
*/
extern WXDLLIMPEXP_DATA_BASE(wxAnyValueType*) wxAnyNullValueType;


//
// We need to implement custom signed/unsigned int equals operators
// for signed/unsigned (eg. wxAny(128UL) == 128L) comparisons to work.
#define WXANY_IMPLEMENT_INT_EQ_OP(TS, TUS) \
bool operator==(TS value) const \
{ \
    if ( wxAnyValueTypeImpl<TS>::IsSameClass(m_type) ) \
        return (value == static_cast<TS> \
                (wxAnyValueTypeImpl<TS>::GetValue(m_buffer))); \
    if ( wxAnyValueTypeImpl<TUS>::IsSameClass(m_type) ) \
        return (value == static_cast<TS> \
                (wxAnyValueTypeImpl<TUS>::GetValue(m_buffer))); \
    return false; \
} \
bool operator==(TUS value) const \
{ \
    if ( wxAnyValueTypeImpl<TUS>::IsSameClass(m_type) ) \
        return (value == static_cast<TUS> \
                (wxAnyValueTypeImpl<TUS>::GetValue(m_buffer))); \
    if ( wxAnyValueTypeImpl<TS>::IsSameClass(m_type) ) \
        return (value == static_cast<TUS> \
                (wxAnyValueTypeImpl<TS>::GetValue(m_buffer))); \
    return false; \
}


#if wxUSE_VARIANT

// Note that the following functions are implemented outside wxAny class
// so that it can reside entirely in header and lack the export declaration.

// Helper function used to associate wxAnyValueType with a wxVariantData.
extern WXDLLIMPEXP_BASE void
wxPreRegisterAnyToVariant(wxAnyToVariantRegistration* reg);

// This function performs main wxAny to wxVariant conversion duties.
extern WXDLLIMPEXP_BASE bool
wxConvertAnyToVariant(const wxAny& any, wxVariant* variant);

#endif // wxUSE_VARIANT


//
// The wxAny class represents a container for any type. A variant's value
// can be changed at run time, possibly to a different type of value.
//
// As standard, wxAny can store value of almost any type, in a fairly
// optimal manner even.
//
class wxAny
{
public:
    /**
        Default constructor.
    */
    wxAny()
    {
        m_type = wxAnyNullValueType;
    }

    /**
        Destructor.
    */
    ~wxAny()
    {
        m_type->DeleteValue(m_buffer);
    }

    //@{
    /**
        Various constructors.
    */
    template<typename T>
    wxAny(const T& value)
    {
        m_type = wxAnyValueTypeImpl<T>::sm_instance.get();
        wxAnyValueTypeImpl<T>::SetValue(value, m_buffer);
    }

    // These two constructors are needed to deal with string literals
    wxAny(const char* value)
    {
        m_type = wxAnyValueTypeImpl<const char*>::sm_instance.get();
        wxAnyValueTypeImpl<const char*>::SetValue(value, m_buffer);
    }
    wxAny(const wchar_t* value)
    {
        m_type = wxAnyValueTypeImpl<const wchar_t*>::sm_instance.get();
        wxAnyValueTypeImpl<const wchar_t*>::SetValue(value, m_buffer);
    }

    wxAny(const wxAny& any)
    {
        m_type = wxAnyNullValueType;
        AssignAny(any);
    }

#if wxUSE_VARIANT
    wxAny(const wxVariant& variant)
    {
        m_type = wxAnyNullValueType;
        AssignVariant(variant);
    }
#endif

    //@}

    /**
        Use this template function for checking if this wxAny holds
        a specific C++ data type.

        @remarks This template function does not work on some older compilers
                (such as Visual C++ 6.0). For full compiler ccompatibility
                please use wxANY_CHECK_TYPE(any, T) macro instead.

        @see wxAnyValueType::CheckType()
    */
    // FIXME-VC6: remove this hack when VC6 is no longer supported
    template <typename T>
    bool CheckType(T* = NULL) const
    {
        return m_type->CheckType<T>();
    }

    /**
        Returns the value type as wxAnyValueType instance.

        @remarks You cannot reliably test whether two wxAnys are of
                 same value type by simply comparing return values
                 of wxAny::GetType(). Instead, use wxAny::HasSameType().

        @see HasSameType()
    */
    const wxAnyValueType* GetType() const
    {
        return m_type;
    }

    /**
        Returns @true if this and another wxAny have the same
        value type.
    */
    bool HasSameType(const wxAny& other) const
    {
        return GetType()->IsSameType(other.GetType());
    }

    /**
        Tests if wxAny is null (that is, whether there is no data).
    */
    bool IsNull() const
    {
        return (m_type == wxAnyNullValueType);
    }

    /**
        Makes wxAny null (that is, clears it).
    */
    void MakeNull()
    {
        m_type->DeleteValue(m_buffer);
        m_type = wxAnyNullValueType;
    }

    //@{
    /**
        Assignment operators.
    */
    template<typename T>
    wxAny& operator=(const T &value)
    {
        m_type->DeleteValue(m_buffer);
        m_type = wxAnyValueTypeImpl<T>::sm_instance.get();
        wxAnyValueTypeImpl<T>::SetValue(value, m_buffer);
        return *this;
    }

    wxAny& operator=(const wxAny &any)
    {
        if (this != &any)
            AssignAny(any);
        return *this;
    }

#if wxUSE_VARIANT
    wxAny& operator=(const wxVariant &variant)
    {
        AssignVariant(variant);
        return *this;
    }
#endif

    // These two operators are needed to deal with string literals
    wxAny& operator=(const char* value)
    {
        Assign(value);
        return *this;
    }
    wxAny& operator=(const wchar_t* value)
    {
        Assign(value);
        return *this;
    }

    //@{
    /**
        Equality operators.
    */
    bool operator==(const wxString& value) const
    {
        wxString value2;
        if ( !GetAs(&value2) )
            return false;
        return value == value2;
    }

    bool operator==(const char* value) const
        { return (*this) == wxString(value); }
    bool operator==(const wchar_t* value) const
        { return (*this) == wxString(value); }

    //
    // We need to implement custom signed/unsigned int equals operators
    // for signed/unsigned (eg. wxAny(128UL) == 128L) comparisons to work.
    WXANY_IMPLEMENT_INT_EQ_OP(signed char, unsigned char)
    WXANY_IMPLEMENT_INT_EQ_OP(signed short, unsigned short)
    WXANY_IMPLEMENT_INT_EQ_OP(signed int, unsigned int)
    WXANY_IMPLEMENT_INT_EQ_OP(signed long, unsigned long)
#ifdef wxLongLong_t
    WXANY_IMPLEMENT_INT_EQ_OP(wxLongLong_t, wxULongLong_t)
#endif

    wxGCC_WARNING_SUPPRESS(float-equal)

    bool operator==(float value) const
    {
        if ( !wxAnyValueTypeImpl<float>::IsSameClass(m_type) )
            return false;

        return value ==
            static_cast<float>
                (wxAnyValueTypeImpl<float>::GetValue(m_buffer));
    }

    bool operator==(double value) const
    {
        if ( !wxAnyValueTypeImpl<double>::IsSameClass(m_type) )
            return false;

        return value ==
            static_cast<double>
                (wxAnyValueTypeImpl<double>::GetValue(m_buffer));
    }

    wxGCC_WARNING_RESTORE(float-equal)

    bool operator==(bool value) const
    {
        if ( !wxAnyValueTypeImpl<bool>::IsSameClass(m_type) )
            return false;

        return value == (wxAnyValueTypeImpl<bool>::GetValue(m_buffer));
    }

    //@}

    //@{
    /**
        Inequality operators (implement as template).
    */
    template<typename T>
    bool operator!=(const T& value) const
        { return !((*this) == value); }
    //@}

    /**
        This template function converts wxAny into given type. In most cases
        no type conversion is performed, so if the type is incorrect an
        assertion failure will occur.

        @remarks For convenience, conversion is done when T is wxString. This
                 is useful when a string literal (which are treated as
                 const char* and const wchar_t*) has been assigned to wxAny.

                 This template function may not work properly with Visual C++
                 6. For full compiler compatibility, please use
                 wxANY_AS(any, T) macro instead.
    */
    // FIXME-VC6: remove this hack when VC6 is no longer supported
    template<typename T>
    T As(T* = NULL) const
    {
        if ( !wxAnyValueTypeImpl<T>::IsSameClass(m_type) )
        {
            wxFAIL_MSG("Incorrect or non-convertible data type");
        }

        return static_cast<T>(wxAnyValueTypeImpl<T>::GetValue(m_buffer));
    }

    // Allow easy conversion from 'const char *' etc. to wxString
    // FIXME-VC6: remove this hack when VC6 is no longer supported
    //template<>
    wxString As(wxString*) const
    {
        wxString value;
        if ( !GetAs(&value) )
        {
            wxFAIL_MSG("Incorrect or non-convertible data type");
        }
        return value;
    }

#if wxUSE_EXTENDED_RTTI
    const wxTypeInfo* GetTypeInfo() const
    {
        return m_type->GetTypeInfo();
    }
#endif
    /**
        Template function that retrieves and converts the value of this
        variant to the type that T* value is.

        @return Returns @true if conversion was successful.
    */
    template<typename T>
    bool GetAs(T* value) const
    {
        if ( !wxAnyValueTypeImpl<T>::IsSameClass(m_type) )
        {
            wxAnyValueType* otherType =
                wxAnyValueTypeImpl<T>::sm_instance.get();
            wxAnyValueBuffer temp_buf;

            if ( !m_type->ConvertValue(m_buffer, otherType, temp_buf) )
                return false;

            *value =
                static_cast<T>(wxAnyValueTypeImpl<T>::GetValue(temp_buf));
            otherType->DeleteValue(temp_buf);

            return true;
        }
        *value = static_cast<T>(wxAnyValueTypeImpl<T>::GetValue(m_buffer));
        return true;
    }

#if wxUSE_VARIANT
    // GetAs() wxVariant specialization
    bool GetAs(wxVariant* value) const
    {
        return wxConvertAnyToVariant(*this, value);
    }
#endif

private:
    // Assignment functions
    void AssignAny(const wxAny& any)
    {
        // Must delete value - CopyBuffer() never does that
        m_type->DeleteValue(m_buffer);

        wxAnyValueType* newType = any.m_type;

        if ( !newType->IsSameType(m_type) )
            m_type = newType;

        newType->CopyBuffer(any.m_buffer, m_buffer);
    }

#if wxUSE_VARIANT
    void AssignVariant(const wxVariant& variant)
    {
        wxVariantData* data = variant.GetData();

        if ( data && data->GetAsAny(this) )
            return;

        m_type->DeleteValue(m_buffer);

        if ( variant.IsNull() )
        {
            // Init as Null
            m_type = wxAnyNullValueType;
        }
        else
        {
            // If everything else fails, wrap the whole wxVariantData
            m_type = wxAnyValueTypeImpl<wxVariantData*>::sm_instance.get();
            wxAnyValueTypeImpl<wxVariantData*>::SetValue(data, m_buffer);
        }
    }
#endif

    template<typename T>
    void Assign(const T &value)
    {
        m_type->DeleteValue(m_buffer);
        m_type = wxAnyValueTypeImpl<T>::sm_instance.get();
        wxAnyValueTypeImpl<T>::SetValue(value, m_buffer);
    }

    // Data
    wxAnyValueBuffer    m_buffer;
    wxAnyValueType*     m_type;
};


//
// This method of checking the type is compatible with VC6
#define wxANY_CHECK_TYPE(any, T) \
    wxANY_VALUE_TYPE_CHECK_TYPE((any).GetType(), T)


//
// This method of getting the value is compatible with VC6
#define wxANY_AS(any, T) \
    (any).As(static_cast<T*>(NULL))


template<typename T>
inline bool wxAnyValueType::CheckType(T* reserved) const
{
    wxUnusedVar(reserved);
    return wxAnyValueTypeImpl<T>::IsSameClass(this);
}

WX_DECLARE_LIST_WITH_DECL(wxAny, wxAnyList, class WXDLLIMPEXP_BASE);

#endif // wxUSE_ANY

#endif // _WX_ANY_H_