Ejemplo n.º 1
0
bool Object::equal(const Object& v2) const {
  if (m_px == v2.get()) {
    return true;
  }
  if (!m_px || !v2.get()) {
    return false;
  }
  if (m_px->isCollection()) {
    return collectionEquals(m_px, v2.get());
  }
  if (UNLIKELY(m_px->instanceof(SystemLib::s_DateTimeInterfaceClass))) {
    return c_DateTime::GetTimestamp(*this) ==
        c_DateTime::GetTimestamp(v2);
  }
  if (v2.get()->getVMClass() != m_px->getVMClass()) {
    return false;
  }
  if (UNLIKELY(m_px->instanceof(SystemLib::s_ArrayObjectClass))) {
    // Compare the whole object, not just the array representation
    Array ar1(ArrayData::Create());
    Array ar2(ArrayData::Create());
    m_px->o_getArray(ar1, false);
    v2->o_getArray(ar2, false);
    return ar1->equal(ar2.get(), false);
  }
  return toArray().equal(v2.toArray());
}
Ejemplo n.º 2
0
TEST(MSGPACK_ARRAY_REF, object_with_zone_array_unsigned_char)
{
    std::array<unsigned char, 3> v { { 'a', 'b', 'c' } };

    msgpack::type::array_ref<std::array<unsigned char, 3> > ar1 = msgpack::type::make_array_ref(v);
    msgpack::zone z;
    msgpack::object obj(ar1, z);

    EXPECT_EQ(obj.type, msgpack::type::ARRAY);
    std::array<unsigned char, 3> v2;
    msgpack::type::array_ref<std::array<unsigned char, 3> > ar2(v2);
    obj.convert(ar2);
    EXPECT_EQ(ar1, ar2);
}
Ejemplo n.º 3
0
TEST(MSGPACK_ARRAY_REF, object_with_zone_array_char_const)
{
    std::array<char, 3> v { { 'a', 'b', 'c' } };

    std::array<char, 3> const& cv = v;

    msgpack::type::array_ref<std::array<char, 3> const> ar1 = msgpack::type::make_array_ref(cv);
    msgpack::zone z;
    msgpack::object obj(ar1, z);

    EXPECT_EQ(obj.type, msgpack::type::ARRAY);
    std::array<char, 3> v2;
    msgpack::type::array_ref<std::array<char, 3> > ar2(v2);
    obj.convert(ar2);
    EXPECT_EQ(ar1, ar2);
}
Ejemplo n.º 4
0
TEST(MSGPACK_ARRAY_REF, pack_unpack_convert_array_unsigned_char)
{
    std::array<unsigned char, 3> v { { 'a', 'b', 'c' } };

    msgpack::type::array_ref<std::array<unsigned char, 3> > ar1 = msgpack::type::make_array_ref(v);
    std::stringstream ss;
    msgpack::pack(ss, ar1);

    msgpack::unpacked upd;
    msgpack::unpack(upd, ss.str().data(), ss.str().size());
    EXPECT_EQ(upd.get().type, msgpack::type::ARRAY);
    std::array<unsigned char, 3> v2;
    msgpack::type::array_ref<std::array<unsigned char, 3> > ar2(v2);
    upd.get().convert(ar2);
    EXPECT_EQ(ar1, ar2);
}
Ejemplo n.º 5
0
TEST(MSGPACK_ARRAY_REF, object_with_zone_vector_char)
{
    std::vector<char> v;
    v.push_back('a');
    v.push_back('b');
    v.push_back('c');

    msgpack::type::array_ref<std::vector<char> > ar1 = msgpack::type::make_array_ref(v);
    msgpack::zone z;
    msgpack::object obj(ar1, z);

    EXPECT_EQ(obj.type, msgpack::type::ARRAY);
    std::vector<char> v2;
    msgpack::type::array_ref<std::vector<char> > ar2(v2);
    obj.convert(ar2);
    EXPECT_EQ(ar1, ar2);
}
Ejemplo n.º 6
0
TEST(MSGPACK_ARRAY_REF, pack_unpack_convert_vector_unsigned_char)
{
    std::vector<unsigned char> v;
    v.push_back('a');
    v.push_back('b');
    v.push_back('c');

    msgpack::type::array_ref<std::vector<unsigned char> > ar1 = msgpack::type::make_array_ref(v);
    std::stringstream ss;
    msgpack::pack(ss, ar1);

    msgpack::unpacked upd;
    msgpack::unpack(upd, ss.str().data(), ss.str().size());
    EXPECT_EQ(upd.get().type, msgpack::type::ARRAY);
    std::vector<unsigned char> v2;
    msgpack::type::array_ref<std::vector<unsigned char> > ar2(v2);
    upd.get().convert(ar2);
    EXPECT_EQ(ar1, ar2);
}
Ejemplo n.º 7
0
int main()
{
    CMapStringToString map;

    if( !map.IsEmpty() ) _fail;
    if( map.GetCount() != 0 ) _fail;
    if( map.GetSize() != 0 ) _fail;

    map.SetAt( _T("0"), _T(" ") );
    map.SetAt( _T("1"), _T("A") );
    map.SetAt( _T("2"), _T("B") );

    CString value;
    if( !map.Lookup( _T("0"), value ) ) _fail;
    if( value != _T(" ") ) _fail;
    if( !map.Lookup( _T("1"), value ) ) _fail;
    if( value != _T("A") ) _fail;
    if( !map.Lookup( _T("2"), value ) ) _fail;
    if( value != _T("B") ) _fail;
    if( map.Lookup( _T("3"), value ) ) _fail;

    POSITION    position = map.GetStartPosition();
    CString     key;
    BOOL        bFound0 = FALSE;
    BOOL        bFound1 = FALSE;
    BOOL        bFound2 = FALSE;
    while( position != NULL ) {
        map.GetNextAssoc( position, key, value );
        if( key == _T("0") ) {
            if( bFound0 ) _fail;
            if( value != _T(" ") ) _fail;
            bFound0 = TRUE;
        } else if( key == _T("1") ) {
            if( bFound1 ) _fail;
            if( value != _T("A") ) _fail;
            bFound1 = TRUE;
        } else if( key == _T("2") ) {
            if( bFound2 ) _fail;
            if( value != _T("B") ) _fail;
            bFound2 = TRUE;
        } else {
            _fail;
        }
    }
    if( !bFound0 ) _fail;
    if( !bFound1 ) _fail;
    if( !bFound2 ) _fail;

    map.RemoveKey( _T("0") );
    if( map.Lookup( _T("0"), value ) ) _fail;

    CMapStringToString smap1;
    CMapStringToString smap2;
    smap1[_T("0")] = _T(" ");
    smap1[_T("1")] = _T("A");
    smap1[_T("2")] = _T("B");
    
    CMemFile file;
    CArchive ar( &file, CArchive::store );
    smap1.Serialize( ar );
    ar.Close();

    file.Seek( 0, CFile::begin );
    CArchive ar2( &file, CArchive::load );
    smap2.Serialize( ar2 );
    ar2.Close();

    if( smap2[_T("0")] != _T(" ") ) _fail;
    if( smap2[_T("1")] != _T("A") ) _fail;
    if( smap2[_T("2")] != _T("B") ) _fail;

    _PASS;
}
Ejemplo n.º 8
0
int main()
{
    for( int i = 1; i <= 5; i++ ) {
        CIntArray arr1;
        CIntArray arr2;
        CIntArray arr3;

        arr1.SetSize( 0, i );
        arr2.SetSize( 0, i );
        arr3.SetSize( 0, i );

        if( !arr1.IsEmpty() ) _fail;

        arr1.Add( 0 );
        arr1.Add( 1 );
        arr1.Add( 2 );
        arr2.Add( 3 );
        arr2.Add( 4 );
        arr2.Add( 5 );
        arr1.Append( arr2 );
        arr3.Copy( arr1 );
        arr3.SetAt( 0, 1 );
        arr3.RemoveAt( 1 );

        if( arr3.GetAt( 0 ) != 1 ) _fail;
        if( arr3.GetAt( 1 ) != 2 ) _fail;
        if( arr3.GetAt( 2 ) != 3 ) _fail;
        if( arr3.GetAt( 3 ) != 4 ) _fail;
        if( arr3.GetAt( 4 ) != 5 ) _fail;
        if( arr3.GetSize() != 5 ) _fail;
        if( arr3.GetUpperBound() != 4 ) _fail;

        arr1.Copy( arr2 );
        arr1.InsertAt( 1, 1, 2 );
        if( arr1.GetAt( 0 ) != 3 ) _fail;
        if( arr1.GetAt( 1 ) != 1 ) _fail;
        if( arr1.GetAt( 2 ) != 1 ) _fail;
        if( arr1.GetAt( 3 ) != 4 ) _fail;
        if( arr1.GetAt( 4 ) != 5 ) _fail;
        if( arr1.GetSize() != 5 ) _fail;
        if( arr1.GetUpperBound() != 4 ) _fail;

        arr1.Copy( arr2 );
        arr1.InsertAt( 1, &arr2 );
        arr1.SetAtGrow( 7, 6 );
        if( arr1.GetAt( 0 ) != 3 ) _fail;
        if( arr1.GetAt( 1 ) != 3 ) _fail;
        if( arr1.GetAt( 2 ) != 4 ) _fail;
        if( arr1.GetAt( 3 ) != 5 ) _fail;
        if( arr1.GetAt( 4 ) != 4 ) _fail;
        if( arr1.GetAt( 5 ) != 5 ) _fail;
        if( arr1.GetAt( 6 ) != 0 ) _fail;
        if( arr1.GetAt( 7 ) != 6 ) _fail;
        if( arr1.GetSize() != 8 ) _fail;
        if( arr1.GetUpperBound() != 7 ) _fail;

        arr1.SetSize( 10 );
        if( arr1.GetSize() != 10 ) _fail;
        if( arr1.GetUpperBound() != 9 ) _fail;
        if( arr1.GetAt( 8 ) != 0 ) _fail;
        if( arr1.GetAt( 9 ) != 0 ) _fail;
    }

    CIntArray sarr1;
    CIntArray sarr2;
    sarr1.SetSize( 10 );
    for( int i = 0; i < 10; i++ ) {
        sarr1.SetAt( i, i );
    }
    
    CMemFile file;
    CArchive ar( &file, CArchive::store );
    sarr1.Serialize( ar );
    ar.Close();

    file.Seek( 0, CFile::begin );
    CArchive ar2( &file, CArchive::load );
    sarr2.Serialize( ar2 );
    ar2.Close();

    if( sarr1.GetSize() != sarr2.GetSize() ) _fail;
    for( int i = 0; i < sarr1.GetSize(); i++ ) {
        if( sarr1.GetAt( i ) != sarr2.GetAt( i ) ) _fail;
    }

    _PASS;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
    // Initialize POOMA and output stream, using Tester class
    Pooma::initialize(argc, argv);
    Pooma::Tester tester(argc, argv);

    tester.out() << argv[0]
                 << ": Tests of expressions with multipatch."
                 << std::endl;
    tester.out() << "------------------------------------------------"
                 << std::endl;

    int size = 30;

    int from = 0;
    int to = size-1;
    int fromInterior = 0;
    int toInterior = size-1;

    int loc1 = 4;
    int loc2 = 14;
    int loc3 = 22;

    Interval<1> dom(from,to);
    Interval<1> I(fromInterior,toInterior);

    Interval<1> domain(size);

    UniformGridPartition<1> partition(Loc<1>(10),GuardLayers<1>(1));
    UniformGridLayout<1> layout(domain,partition,ReplicatedTag());

    Array<1,double,MultiPatch<UniformTag,Brick> >
    a1(layout), a2(layout), a3(layout), a4(layout), initial(layout);

    initial = 0.0;

    Pooma::blockAndEvaluate();

    initial(loc1) = 2.0;
    initial(loc2) = 3.0;
    initial(loc3) = 4.0;

    test1(tester, 1, a1, a2, a3, a4, initial, I);
    test2(tester, 2, a1, a2, a3, a4, initial, I);
    test3(tester, 3, a1, a2, a3, a4, initial, I);
    test4(tester, 4, a1, a2, a3, a4, initial, I);

    Array<1,Vector<2,double>,MultiPatch<UniformTag,Brick> >
    av1(layout),av2(layout),av3(layout),av4(layout),
        initialv(layout);

    initialv = Vector<2,double>(0.0,0.0);

    Pooma::blockAndEvaluate();

    initialv(loc1) = Vector<2,double>(2.0,3.0);
    initialv(loc2) = Vector<2,double>(3.0,-1.0);
    initialv(loc3) = Vector<2,double>(4.0,-5.0);

    test5(tester, 5, av1, av2, av3, av4, initialv, I);
    test1(tester, 6, av1, av2, av3, av4, initialv, I);
    test4(tester, 7, av1, av2, av3, av4, initialv, I);

    UniformGridLayout<1> layoutr(domain, partition, DistributedTag());

    Array<1, double, MultiPatch<UniformTag, Remote<Brick> > >
    ar1(layoutr), ar2(layoutr), ar3(layoutr), ar4(layoutr);

    test1(tester, 8,  ar1, ar2, ar3, ar4, initial, I);
    test2(tester, 9,  ar1, ar2, ar3, ar4, initial, I);
    test3(tester, 10, ar1, ar2, ar3, ar4, initial, I);
    test4(tester, 11, ar1, ar2, ar3, ar4, initial, I);

    tester.out() << "------------------------------------------------"
                 << std::endl;

    int retval = tester.results("array_test18");
    Pooma::finalize();
    return retval;
}
Ejemplo n.º 10
0
static void testrotations()
{
    ap::real_2d_array al1;
    ap::real_2d_array al2;
    ap::real_2d_array ar1;
    ap::real_2d_array ar2;
    ap::real_1d_array cl;
    ap::real_1d_array sl;
    ap::real_1d_array cr;
    ap::real_1d_array sr;
    ap::real_1d_array w;
    int m;
    int n;
    int maxmn;
    double t;
    int pass;
    int passcount;
    int i;
    int j;
    double err;
    double maxerr;
    bool isforward;

    passcount = 1000;
    maxerr = 0;
    for(pass = 1; pass <= passcount; pass++)
    {
        
        //
        // settings
        //
        m = 2+ap::randominteger(50);
        n = 2+ap::randominteger(50);
        isforward = ap::randomreal()>0.5;
        maxmn = ap::maxint(m, n);
        al1.setbounds(1, m, 1, n);
        al2.setbounds(1, m, 1, n);
        ar1.setbounds(1, m, 1, n);
        ar2.setbounds(1, m, 1, n);
        cl.setbounds(1, m-1);
        sl.setbounds(1, m-1);
        cr.setbounds(1, n-1);
        sr.setbounds(1, n-1);
        w.setbounds(1, maxmn);
        
        //
        // matrices and rotaions
        //
        for(i = 1; i <= m; i++)
        {
            for(j = 1; j <= n; j++)
            {
                al1(i,j) = 2*ap::randomreal()-1;
                al2(i,j) = al1(i,j);
                ar1(i,j) = al1(i,j);
                ar2(i,j) = al1(i,j);
            }
        }
        for(i = 1; i <= m-1; i++)
        {
            t = 2*ap::pi()*ap::randomreal();
            cl(i) = cos(t);
            sl(i) = sin(t);
        }
        for(j = 1; j <= n-1; j++)
        {
            t = 2*ap::pi()*ap::randomreal();
            cr(j) = cos(t);
            sr(j) = sin(t);
        }
        
        //
        // Test left
        //
        applyrotationsfromtheleft(isforward, 1, m, 1, n, cl, sl, al1, w);
        for(j = 1; j <= n; j++)
        {
            applyrotationsfromtheleft(isforward, 1, m, j, j, cl, sl, al2, w);
        }
        err = 0;
        for(i = 1; i <= m; i++)
        {
            for(j = 1; j <= n; j++)
            {
                err = ap::maxreal(err, fabs(al1(i,j)-al2(i,j)));
            }
        }
        maxerr = ap::maxreal(err, maxerr);
        
        //
        // Test right
        //
        applyrotationsfromtheright(isforward, 1, m, 1, n, cr, sr, ar1, w);
        for(i = 1; i <= m; i++)
        {
            applyrotationsfromtheright(isforward, i, i, 1, n, cr, sr, ar2, w);
        }
        err = 0;
        for(i = 1; i <= m; i++)
        {
            for(j = 1; j <= n; j++)
            {
                err = ap::maxreal(err, fabs(ar1(i,j)-ar2(i,j)));
            }
        }
        maxerr = ap::maxreal(err, maxerr);
    }
    printf("TESTING ROTATIONS\n");
    printf("Pass count %0ld\n",
        long(passcount));
    printf("Error is %5.3le\n",
        double(maxerr));
}
Ejemplo n.º 11
0
void CV_SolvePolyTest::run( int )
{
    CvRNG rng = cvRNG();
    int fig = 100;
    double range = 50;
    double err_eps = 1e-4;

    for (int idx = 0, max_idx = 1000, progress = 0; idx < max_idx; ++idx)
    {
        progress = update_progress(progress, idx-1, max_idx, 0);
        int n = cvRandInt(&rng) % 13 + 1;
        std::vector<complex_type> r(n), ar(n), c(n + 1, 0);
        std::vector<double> a(n + 1), u(n * 2), ar1(n), ar2(n);

        int rr_odds = 3; // odds that we get a real root
        for (int j = 0; j < n;)
        {
            if (cvRandInt(&rng) % rr_odds == 0 || j == n - 1)
	            r[j++] = cvRandReal(&rng) * range;
            else
            {
	            r[j] = complex_type(cvRandReal(&rng) * range,
			    cvRandReal(&rng) * range + 1);
	            r[j + 1] = std::conj(r[j]);
	            j += 2;
            }
        }

        for (int j = 0, k = 1 << n, jj, kk; j < k; ++j)
        {
            int p = 0;
            complex_type v(1);
            for (jj = 0, kk = 1; jj < n && !(j & kk); ++jj, ++p, kk <<= 1)
                ;
            for (; jj < n; ++jj, kk <<= 1)
            {
	            if (j & kk)
	                v *= -r[jj];
	            else
	                ++p;
            }
            c[p] += v;
        }

        bool pass = false;
        double div = 0, s = 0;
        int cubic_case = idx & 1;
        for (int maxiter = 100; !pass && maxiter < 10000; maxiter *= 2, cubic_case = (cubic_case + 1) % 2)
        {
            for (int j = 0; j < n + 1; ++j)
	            a[j] = c[j].real();

            CvMat amat, umat;
            cvInitMatHeader(&amat, n + 1, 1, CV_64FC1, &a[0]);
            cvInitMatHeader(&umat, n, 1, CV_64FC2, &u[0]);
            cvSolvePoly(&amat, &umat, maxiter, fig);

            for (int j = 0; j < n; ++j)
	            ar[j] = complex_type(u[j * 2], u[j * 2 + 1]);

            sort(r.begin(), r.end(), pred_complex());
            sort(ar.begin(), ar.end(), pred_complex());

            pass = true;
            if( n == 3 )
            {
                ar2.resize(n);
                cv::Mat _umat2(3, 1, CV_64F, &ar2[0]), umat2 = _umat2;
                cvFlip(&amat, &amat, 0);
                int nr2;
                if( cubic_case == 0 )
                    nr2 = cv::solveCubic(cv::Mat(&amat),umat2);
                else
                    nr2 = cv::solveCubic(cv::Mat_<float>(cv::Mat(&amat)), umat2);
                cvFlip(&amat, &amat, 0);
                if(nr2 > 0)
                    sort(ar2.begin(), ar2.begin()+nr2, pred_double());
                ar2.resize(nr2);

                int nr1 = 0;
                for(int j = 0; j < n; j++)
                    if( fabs(r[j].imag()) < DBL_EPSILON )
                        ar1[nr1++] = r[j].real();

                pass = pass && nr1 == nr2;
                if( nr2 > 0 )
                {
                    div = s = 0;
                    for(int j = 0; j < nr1; j++)
                    {
                        s += fabs(ar1[j]);
                        div += fabs(ar1[j] - ar2[j]);
                    }
                    div /= s;
                    pass = pass && div < err_eps;
                }
            }

            div = s = 0;
            for (int j = 0; j < n; ++j)
            {
                s += fabs(r[j].real()) + fabs(r[j].imag());
                div += sqrt(pow(r[j].real() - ar[j].real(), 2) + pow(r[j].imag() - ar[j].imag(), 2));
            }
            div /= s;
            pass = pass && div < err_eps;
        }

        if (!pass)
        {
            ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
            ts->printf( CvTS::LOG, "too big diff = %g\n", div );

            for (size_t j=0;j<ar2.size();++j)
                ts->printf( CvTS::LOG, "ar2[%d]=%g\n", j, ar2[j]);
            ts->printf(CvTS::LOG, "\n");

            for (size_t j=0;j<r.size();++j)
	            ts->printf( CvTS::LOG, "r[%d]=(%g, %g)\n", j, r[j].real(), r[j].imag());
            ts->printf( CvTS::LOG, "\n" );
            for (size_t j=0;j<ar.size();++j)
	            ts->printf( CvTS::LOG, "ar[%d]=(%g, %g)\n", j, ar[j].real(), ar[j].imag());
            break;
        }
    }
}
Ejemplo n.º 12
0
// test drawing with strips of fading gradient above and below
static void test_fade(SkCanvas* canvas) {
    SkAutoCanvasRestore ar(canvas, true);

    SkRect r;

    SkPaint p;
    p.setAlpha(0x88);

    SkAutoCanvasRestore ar2(canvas, false);

    // create the layers

    r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100));
    canvas->clipRect(r);

    r.fBottom = SkIntToScalar(20);
    canvas->saveLayer(&r, nullptr);

    r.fTop = SkIntToScalar(80);
    r.fBottom = SkIntToScalar(100);
    canvas->saveLayer(&r, nullptr);

    // now draw the "content"

    if (true) {
        r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100));

        canvas->saveLayerAlpha(&r, 0x80);

        SkPaint p;
        p.setColor(SK_ColorRED);
        p.setAntiAlias(true);
        canvas->drawOval(r, p);

        dump_layers("inside layer alpha", canvas);

        canvas->restore();
    } else {
        r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100));

        SkPaint p;
        p.setColor(SK_ColorRED);
        p.setAntiAlias(true);
        canvas->drawOval(r, p);
    }

//    return;

    dump_layers("outside layer alpha", canvas);

    // now apply an effect
    SkMatrix m;
    m.setScale(SK_Scalar1, -SK_Scalar1);
    m.postTranslate(0, SkIntToScalar(100));

    SkPaint paint;
    make_paint(&paint, m);
    r.set(0, 0, SkIntToScalar(100), SkIntToScalar(20));
//    SkDebugf("--------- draw top grad\n");
    canvas->drawRect(r, paint);

    r.fTop = SkIntToScalar(80);
    r.fBottom = SkIntToScalar(100);
//    SkDebugf("--------- draw bot grad\n");
    canvas->drawRect(r, paint);
}
Ejemplo n.º 13
0
///////////////////////////////////////////////////
//Copy this object out to the clipboard or drag/drop
//buffer based on Keith Rule's
//serialization algorithm
//from the MFC Programmer's Sourcebook website,
//and Chapter 1 of "the Essence of OLE with Active X"
//by David S. Platt.
//
//pDropEffect is only set if doing a drag-drop.
//
//You usually call this function from:
//
//1) Your view class's OnLButtonDown() method
//   when starting a drag-drop.
//
//2) Your document class when copying data
//   to the clipboard.
///////////////////////////////////////////////////
BOOL CDragDropMgr::PrepareDrop(
                   BOOL        bToClipboard,
                   LPCTSTR     lpstrFormat,
                   CObject*    pObj,
                   DROPEFFECT* pDropEffect,
                   LPCTSTR     lpstrFormat2,
                   CObject*    pObj2)
{
    if (pObj == NULL)
        return FALSE;

    CSharedFile sf(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);
    CSharedFile sf2(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);

    UINT format = ::RegisterClipboardFormat(lpstrFormat);

    if (format == 0)
        return FALSE;

    TRY
    {
        CArchive ar(&sf, CArchive::store);

        pObj->Serialize(ar);

        ar.Close();

        HGLOBAL hMem = sf.Detach();

        if (hMem == NULL)
            return FALSE;

        COleDataSource* pSrc = new COleDataSource();

        if (pSrc == NULL)
            return FALSE;
    
        pSrc->CacheGlobalData(format,hMem);

		if (pObj2) { // special case for when the second data type is a filelist
			UINT format2 = (strcmp(lpstrFormat2, "CF_HDROP") ? ::RegisterClipboardFormat(lpstrFormat2) : CF_HDROP);
			if (format2 != CF_HDROP) {
				CArchive ar2(&sf2, CArchive::store);

				pObj2->Serialize(ar2);
		
				ar2.Close();

				HGLOBAL hMem2 = sf2.Detach();

				if (hMem2 == NULL)
					return FALSE;

				pSrc->CacheGlobalData(format2,hMem2);
			}
			else { // fake file list
				DROPFILES *pDrop = (DROPFILES*)pObj2;
				HGLOBAL hgDrop = GlobalAlloc ( GHND | GMEM_SHARE, sizeof(DROPFILES)+1 );
				DROPFILES *pDrop2 = (DROPFILES*) GlobalLock ( hgDrop );
				memcpy((void*)pDrop2, (void*)pDrop, sizeof(DROPFILES)+1);
				GlobalUnlock(hgDrop);
				pSrc->CacheGlobalData(format2, hgDrop);
			}
		}
    
        //Pasting to the clipboard:
        //do not free the data source
        //(OLE will free it when no longer needed)
        if (bToClipboard)
            pSrc->SetClipboard();
    
        //Starting a drag-drop:
        //Set the type of drag-drop effect, and
        //free the data source object.
        //OLE has created a data source object in
        //the drag-drop global cache; it's
        //not our problem anymore...
        else if (pDropEffect != NULL)
        {
            *pDropEffect = pSrc->DoDragDrop();

            delete pSrc;
        }

        return TRUE;
    }   //catch

    CATCH_ALL(ce)
    {
        return FALSE;
    }
    END_CATCH_ALL
}
Ejemplo n.º 14
0
// ######################################################################
int main()
{
  std::cout << std::boolalpha << std::endl;

  {
    std::ofstream os("file.json");
    cereal::JSONOutputArchive oar( os );

    //auto f = std::make_shared<Fixture>();
    //auto f2 = f;
    //oar( f );
    //oar( f2 );
    Stuff s; s.fillData();
    oar( cereal::make_nvp("best data ever", s) );
  }

  {
    std::ifstream is("file.json");
    std::string str((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>());
    std::cout << "---------------------" << std::endl << str << std::endl << "---------------------" << std::endl;
  }

  // playground
  {
    cereal::JSONOutputArchive archive( std::cout );
    bool arr[] = {true, false};
    std::vector<int> vec = {1, 2, 3, 4, 5};
    archive( CEREAL_NVP(vec),
        arr );
    auto f = std::make_shared<Fixture>();
    auto f2 = f;
    archive( f );
    archive( f2 );
  }

  // test out of order
  std::stringstream oos;
  {
    cereal::JSONOutputArchive ar(oos);
    cereal::JSONOutputArchive ar2(std::cout,
        cereal::JSONOutputArchive::Options(2, cereal::JSONOutputArchive::Options::IndentChar::space, 2) );

    ar( cereal::make_nvp( "1", 1 ),
        cereal::make_nvp( "2", 2 ),
        3,
        0, // unused
        cereal::make_nvp( "4", 4 ),
        cereal::make_nvp( "5", 5 ) );

    int x = 33;
    ar.saveBinaryValue( &x, sizeof(int), "bla" );

    ar2( cereal::make_nvp( "1", 1 ),
         cereal::make_nvp( "2", 2 ),
         3,
         0, // unused
         cereal::make_nvp( "4", 4 ),
         cereal::make_nvp( "5", 5 ) );
    ar2.saveBinaryValue( &x, sizeof(int), "bla" );

    OOJson oo( 1, 2, true, 4.2 );
    ar( CEREAL_NVP(oo) );
    ar2( CEREAL_NVP(oo) );

    // boost stuff
    ar & cereal::make_nvp("usingop&", oo ) & 6;
    ar << 5 << 4 << 3;

    ar2 & cereal::make_nvp("usingop&", oo ) & 6;
    ar2 << 5 << 4 << 3;

    long double ld = std::numeric_limits<long double>::max();
    long long ll = std::numeric_limits<long long>::max();
    unsigned long long ull = std::numeric_limits<unsigned long long>::max();

    ar( CEREAL_NVP(ld),
        CEREAL_NVP(ll),
        CEREAL_NVP(ull) );

    ar2( CEREAL_NVP(ld),
         CEREAL_NVP(ll),
         CEREAL_NVP(ull) );
  }

  {
    cereal::JSONInputArchive ar(oos);
    int i1, i2, i3, i4, i5, x;

    ar( i1 );
    ar( cereal::make_nvp( "2", i2 ), i3 );

    ar( cereal::make_nvp( "4", i4 ),
        i5 );

    ar.loadBinaryValue( &x, sizeof(int) );

    OOJson ii;
    ar( cereal::make_nvp("oo", ii) );
    ar( cereal::make_nvp( "2", i2 ) );

    std::cout << i1 << " " << i2 << " " << i3 << " " << i4 << " " << i5 << std::endl;
    std::cout << x << std::endl;
    std::cout << ii.a << " " << ii.b << " " << ii.c.first << " " << ii.c.second << " ";
    for( auto z : ii.d )
      std::cout << z << " ";
    std::cout << std::endl;

    OOJson oo;
    ar >> cereal::make_nvp("usingop&", oo );
    std::cout << oo.a << " " << oo.b << " " << oo.c.first << " " << oo.c.second << " ";
    for( auto z : oo.d )
      std::cout << z << " ";

    int aa, a, b, c;
    ar & aa & a & b & c;
    std::cout << aa << " " << a << " " << b << " " << c << std::endl;

    long double ld;
    long long ll;
    unsigned long long ull;

    ar( CEREAL_NVP(ld),
        CEREAL_NVP(ll),
        CEREAL_NVP(ull) );

    std::cout << (ld  == std::numeric_limits<long double>::max()) << std::endl;
    std::cout << (ll  == std::numeric_limits<long long>::max()) << std::endl;
    std::cout << (ull == std::numeric_limits<unsigned long long>::max()) << std::endl;
  }

  return 0;
}
Ejemplo n.º 15
0
int main()
{
    CMemFile file;
    CArchive ar( &file, CArchive::store );
    ar << TEST_BYTE;
    ar << TEST_WORD;
    ar << TEST_LONG;
    ar << TEST_DWORD;
    ar << TEST_FLOAT;
    ar << TEST_DOUBLE;
    ar << TEST_INT;
    ar << TEST_SHORT;
    ar << TEST_CHAR;
    ar << TEST_WCHAR_T;
    ar << TEST_UNSIGNED;
    ar << TEST_BOOL;
    ar << TEST_ULONGLONG;
    ar << TEST_LONGLONG;
    ar.Close();

    file.Seek( 0, CFile::begin );
    CArchive ar2( &file, CArchive::load );

    BYTE by;
    ar2 >> by;
    if( by != TEST_BYTE ) _fail;

    WORD w;
    ar2 >> w;
    if( w != TEST_WORD ) _fail;

    LONG l;
    ar2 >> l;
    if( l != TEST_LONG ) _fail;

    DWORD dw;
    ar2 >> dw;
    if( dw != TEST_DWORD ) _fail;

    float f;
    ar2 >> f;
    if( f != TEST_FLOAT ) _fail;

    double d;
    ar2 >> d;
    if( d != TEST_DOUBLE ) _fail;

    int i;
    ar2 >> i;
    if( i != TEST_INT ) _fail;

    short s;
    ar2 >> s;
    if( s != TEST_SHORT ) _fail;

    char ch;
    ar2 >> ch;
    if( ch != TEST_CHAR ) _fail;

    wchar_t wc;
    ar2 >> wc;
    if( wc != TEST_WCHAR_T ) _fail;

    unsigned u;
    ar2 >> u;
    if( u != TEST_UNSIGNED ) _fail;

    bool b;
    ar2 >> b;
    if( b != TEST_BOOL ) _fail;

    ULONGLONG ull;
    ar2 >> ull;
    if( ull != TEST_ULONGLONG ) _fail;

    LONGLONG ll;
    ar2 >> ll;
    if( ll != TEST_LONGLONG ) _fail;

    ar2.Close();
    
    _PASS;
}
void plotHitResSim(){
  setTDRStyle();
  gROOT->SetStyle("tdrStyle");

  // load the code before executing the macro:
  gROOT->LoadMacro("TrackingAnalysis/Cosmics/test/OverlapHistos.C+");
  //make sure OverlapHistos.h is pointing to a root file from MC

  ol = new OverlapHistos();
  ol->Loop(); 

  //summary histos written out to main file, histos/detid pair in root->ROOT Memory
  //new TBrowser()

 width->SetLineColor(2);
 width->SetMarkerStyle(24);  //20
 width->SetMarkerColor(2);
 width->GetYaxis()->SetTitle("Uncertainty [#mum]");
 width->SetMinimum(0);
 width->GetXaxis()->SetTitle("");
 width->GetXaxis()->SetLabelSize(0);
 width->GetXaxis()->SetTickLength(0);
 simRec->SetLineColor(4);
 simRec->SetMarkerStyle(25); //21
 simRec->SetMarkerColor(4);
 simTrk->SetMarkerStyle(26); //22
 width->Draw();
 simTrk->Draw("same");
 simRec->Draw("same");

leg_hist = new TLegend(0.12,0.7,0.39,0.89);
leg_hist->AddEntry(width,"Fitted width #Deltax_{hit}-#Deltax_{pred} [#mum]","p");
leg_hist->AddEntry(simTrk,"Fitted width #Deltax_{pred}-#Deltax_{sim}","p");
leg_hist->AddEntry(simRec,"Fitted width #Deltax_{hit}-#Deltax_{sim}","p");
leg_hist->SetTextSize(0.055);
leg_hist->SetFillColor(0);
leg_hist->Draw("same");

  TArrow ar1(0.0,0.0,5.5,0.0,0.05,"<|>");
  ar1.SetArrowSize(0.02); ar1.SetAngle(40);
  ar1.SetLineWidth(2); ar1.Draw();

  TArrow ar3(6,0.0,15.5,0.0,0.05,"<|>");
  ar3.SetArrowSize(0.02); ar3.SetAngle(40);
  ar3.SetLineWidth(2); ar3.Draw();

  TArrow ar4(16,0.0,33.5,0.0,0.05,"<|>");
  ar4.SetArrowSize(0.02); ar4.SetAngle(40);
  ar4.SetLineWidth(2); ar4.Draw();

  TArrow ar5(34,0.0,60.5,0.0,0.05,"<|>");
  ar5.SetArrowSize(0.02); ar5.SetAngle(40);
  ar5.SetLineWidth(2); ar5.Draw();

  TArrow ar2(61,0.0,86,0.0,0.05,"<|>");
  ar2.SetArrowSize(0.02); ar2.SetAngle(40);
  ar2.SetLineWidth(2); ar2.Draw();

  TLatex* taga = new TLatex(.115, .085, "TIB1");
  taga->SetNDC(kTRUE);  taga->SetTextSize(0.04);  taga->Draw();
  TLatex* taga = new TLatex(.19, .085, "TIB2");
  taga->SetNDC(kTRUE);  taga->SetTextSize(0.04);  taga->Draw();
  TLatex* taga = new TLatex(.33, .085, "TIB3");
  taga->SetNDC(kTRUE);  taga->SetTextSize(0.04);  taga->Draw();
  TLatex* taga = new TLatex(.55, .085, "TIB4");
  taga->SetNDC(kTRUE);  taga->SetTextSize(0.04);  taga->Draw();
  TLatex* tagg = new TLatex(.83, .085, "TOB");
  tagg->SetNDC(kTRUE);  tagg->SetTextSize(0.04);  tagg->Draw();

 c1->SaveAs("ResolutionSim.eps");
 // c1->Print("ResolutionSim.pdf","pdf");
 // do epstopdf instead
}
Ejemplo n.º 17
0
void SsValueSeriarizer(ISsXmlArchiver* ar , FSsValue& v , const FString key = "value")
{
	char tmp[32];

	//インプット
	XMLElement* e = ar->getxml();
	if ( key != "" )
	{
#if PLATFORM_WINDOWS
		sprintf_s(tmp, 32, "%S", *key);
#else
		sprintf(tmp, "%S", *key);
#endif
		e = e->FirstChildElement( tmp );
	}
	if ( e )
	{
		XMLElement* child = e->FirstChildElement();

		if ( child == 0 )
		{
			const char* str = e->GetText();

			if (str==0)
			{
				const char* err_log1 = e->Parent()->Value();
				const char* err_log2 = e->Parent()->ToElement()->GetText();
				const char* err_log3 = e->Parent()->Parent()->ToElement()->FirstAttribute()->Value();
				return ;
			}
			
			v = SsValueSeriarizer__MakeValue( str );
		}else{
			XMLElement* ce = child;

			SsHash hash;
			while(ce)
			{
				TCHAR ceName[32];
#if PLATFORM_WINDOWS
				FUTF8ToTCHAR_Convert::Convert(ceName, 32, ce->Name(), strnlen_s(ce->Name(), 32) + 1);
#else
				FUTF8ToTCHAR_Convert::Convert(ceName, 32, ce->Name(), strnlen(ce->Name(), 32) + 1);
#endif
				FName fceName(ceName);
				if(!hash.Contains(fceName))
				{
					hash.Add(fceName);
				}

				const char* str = ce->GetText();
				if ( str != 0 )
				{
					hash[fceName] = SsValueSeriarizer__MakeValue( str );
					ce = (XMLElement*)ce->NextSibling();
				}else{
					//さらに子構造があるようだ
					//さらに子構造があるようだ
					//ce = 0 ;
					SsXmlIArchiver ar2(ce);

					FSsValue tempv;
					SsValueSeriarizer( &ar2 , tempv , "");
					hash[fceName] = tempv;					
					ce = (XMLElement*)ce->NextSibling();
				}
			}

			v = FSsValue(hash);

		}

		return ;
	}
}