2005-10-05 17:57:54 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// The Loki Library
|
|
|
|
|
// Copyright (c) 2005 Peter K<>mmel
|
|
|
|
|
// Permission to use, copy, modify, distribute and sell this software for any
|
|
|
|
|
// purpose is hereby granted without fee, provided that the above copyright
|
|
|
|
|
// notice appear in all copies and that both that copyright notice and this
|
|
|
|
|
// permission notice appear in supporting documentation.
|
|
|
|
|
// The author makes no representations about the
|
|
|
|
|
// suitability of this software for any purpose. It is provided "as is"
|
|
|
|
|
// without express or implied warranty.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2006-01-25 18:34:11 +00:00
|
|
|
|
// $Header$
|
2005-10-05 17:57:54 +00:00
|
|
|
|
|
|
|
|
|
// define to test the OrderedStatic template
|
|
|
|
|
#define TEST_ORDERED_STATIC
|
|
|
|
|
|
|
|
|
|
// define to see a runtime crash when not using OrderedStatic
|
|
|
|
|
//#define LOKI_CLASS_LEVEL_THREADING
|
|
|
|
|
|
2006-01-05 00:23:44 +00:00
|
|
|
|
#include <loki/Functor.h>
|
2005-10-05 17:57:54 +00:00
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_ORDERED_STATIC
|
2006-01-05 00:23:44 +00:00
|
|
|
|
#include <loki/OrderedStatic.h>
|
2005-10-05 17:57:54 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct L1
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
L1(){std::cout << "create L1: " << this << "\n";}
|
|
|
|
|
~L1(){std::cout << "delete L1: " << this <<" \n";}
|
2005-10-05 17:57:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct L2
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
L2(){std::cout << "create L2 \n";}
|
|
|
|
|
~L2(){std::cout << "delete L2 \n";}
|
2005-10-05 17:57:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-10-17 09:43:45 +00:00
|
|
|
|
struct M1
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
M1(){std::cout << "create M1 \n";}
|
|
|
|
|
~M1(){std::cout << "delete M1 \n";}
|
2005-10-17 09:43:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct M2
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
M2(){std::cout << "create M2 \n";}
|
|
|
|
|
~M2(){std::cout << "delete M2 \n";}
|
2005-10-17 09:43:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-10-05 17:57:54 +00:00
|
|
|
|
int f()
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
std::cout << "f called \n";
|
|
|
|
|
return 0;
|
2005-10-05 17:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string func();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_ORDERED_STATIC
|
|
|
|
|
|
2005-10-17 09:43:45 +00:00
|
|
|
|
struct MemberTest
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
static Loki::OrderedStatic<1,M1> m1;
|
|
|
|
|
static Loki::OrderedStatic<2,M2> m2;
|
2005-10-17 09:43:45 +00:00
|
|
|
|
};
|
|
|
|
|
Loki::OrderedStatic<1,M1> MemberTest::m1;
|
|
|
|
|
Loki::OrderedStatic<2,M2> MemberTest::m2;
|
|
|
|
|
|
|
|
|
|
|
2005-10-05 17:57:54 +00:00
|
|
|
|
Loki::OrderedStatic<1,L1> l1;
|
|
|
|
|
Loki::OrderedStatic<2,L2> l2;
|
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
Loki::OrderedStatic<1, std::string, std::string(*)() > s1( &func );
|
|
|
|
|
Loki::OrderedStatic<2, std::string, Loki::Seq<char *> > s2( "s2" );
|
2005-10-05 17:57:54 +00:00
|
|
|
|
|
2005-10-30 13:49:44 +00:00
|
|
|
|
Loki::OrderedStatic<1, Loki::Functor<int>, Loki::Seq<int(*)()> > f1(f);
|
2005-10-05 17:57:54 +00:00
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2005-10-17 09:43:45 +00:00
|
|
|
|
struct MemberTest
|
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
|
static M1 m1;
|
|
|
|
|
static M2 m2;
|
2005-10-17 09:43:45 +00:00
|
|
|
|
};
|
|
|
|
|
M1 MemberTest::m1;
|
|
|
|
|
M2 MemberTest::m2;
|
|
|
|
|
|
2005-10-05 17:57:54 +00:00
|
|
|
|
L1 l1;
|
|
|
|
|
L2 l2;
|
|
|
|
|
|
|
|
|
|
std::string s1( func() );
|
|
|
|
|
std::string s2("s2");
|
|
|
|
|
|
|
|
|
|
Loki::Functor<int> f1(f);
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string func()
|
|
|
|
|
{
|
|
|
|
|
#ifdef TEST_ORDERED_STATIC
|
2005-10-30 14:03:23 +00:00
|
|
|
|
return *s2;
|
2005-10-05 17:57:54 +00:00
|
|
|
|
#else
|
2005-10-30 14:03:23 +00:00
|
|
|
|
return s2;
|
2005-10-05 17:57:54 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
2005-10-30 14:03:23 +00:00
|
|
|
|
{
|
|
|
|
|
|
2005-10-05 17:57:54 +00:00
|
|
|
|
#ifdef TEST_ORDERED_STATIC
|
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
Loki::OrderedStaticManager::Instance().createObjects();
|
|
|
|
|
|
|
|
|
|
std::cout << "\n";
|
2005-10-17 09:43:45 +00:00
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
(*f1)();
|
2005-10-05 17:57:54 +00:00
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
std::cout << "value of s1: " << (*s1).c_str() << "\n";
|
|
|
|
|
std::cout << "value of s2: " << (*s2).c_str() << "\n";
|
|
|
|
|
|
|
|
|
|
std::string s("text11");
|
|
|
|
|
*s1=s;
|
2005-11-20 13:16:04 +00:00
|
|
|
|
std::cout << "value of s1: " << s1->c_str() << "\n";
|
2005-10-30 14:03:23 +00:00
|
|
|
|
|
2005-10-05 17:57:54 +00:00
|
|
|
|
#else
|
2005-10-30 14:03:23 +00:00
|
|
|
|
|
|
|
|
|
std::cout << "\n";
|
|
|
|
|
f1();
|
|
|
|
|
|
|
|
|
|
std::cout << "s1 = " << s1.c_str() << "\n";
|
|
|
|
|
std::cout << "s2 = " << s2.c_str() << "\n";
|
2005-10-05 17:57:54 +00:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
std::cout << "\n";
|
2005-11-20 13:16:04 +00:00
|
|
|
|
|
2006-01-04 23:54:30 +00:00
|
|
|
|
#if defined(__BORLANDC__) || defined(_MSC_VER)
|
|
|
|
|
system("PAUSE");
|
|
|
|
|
#endif
|
2005-11-20 13:16:04 +00:00
|
|
|
|
|
2005-10-30 14:03:23 +00:00
|
|
|
|
return 0;
|
2005-10-05 17:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|