示例#1
0
int main() {
	double j;

	for(j = 0; j < 1; j += 0.1)
		printf("%.20f %.20f %.20f\n", sf1(j), sf2(j), sf1(j) / sf2(j));

	return 0;
}
示例#2
0
void nwxString::UnitTest_FileExt()
{
  wxString sf1("C:/dir1/dir2/foo.dll");
  wxString sf2("C:\\dir3\\dir4\\bar.dll");
#ifdef __WXMSW__
  wxString sf3("C:\\dir5\\dir.6\\xxx");
#else
  wxString sf3("/home/whatever/dir5/dir.6/xxx");
#endif
  nwxString::SetFileExtension(&sf1,"txt");
  nwxString::SetFileExtension(&sf2,".txt");
  nwxString::SetFileExtension(&sf3,".zip");
  bool b1 = (sf1 == "C:/dir1/dir2/foo.txt");
  bool b2 = (sf2 == "C:\\dir3\\dir4\\bar.txt");
#ifdef __WXMSW__
  bool b3 = (sf3 == "C:\\dir5\\dir.6\\xxx.zip");
#else
  bool b3 = (sf3 == "/home/whatever/dir5/dir.6/xxx.zip");
#endif
  if(!(b1 && b2 && b3))
  {
    wxString sfTxt;
    sfTxt.Alloc(256);
    sfTxt = " Problem with File Ext:\n";
    sfTxt.Append(sf1);
    sfTxt.Append("\n");
    sfTxt.Append(sf2);
    sfTxt.Append("\n");
    sfTxt.Append(sf3);
    wxASSERT_MSG(0,sfTxt);
  }
}
STKUNIT_UNIT_TEST(function, stringFunction_multiplePoints)
{
  EXCEPTWATCH;
  MDArray points(NPTS, 3);
  MDArray output(NPTS, 1);
  MDArray output_expect(NPTS, 1);

  StringFunction sf1("x+y*z");
  for (unsigned ipts = 0; ipts < NPTS; ipts++)
  {
    double x = testpoints[ipts][0];
    double y = testpoints[ipts][1];
    double z = testpoints[ipts][2];
    double t = testpoints[ipts][3];
    points(ipts, 0) = x;
    points(ipts, 1) = y;
    points(ipts, 2) = z;
    //points(ipts, 3) = t;

    //std::cout << "stringFunction_op: ipts= " << ipts << std::endl;

    double vx = eval(x, y, z, t, sf1);
    STKUNIT_EXPECT_DOUBLE_EQ(vx, x+y*z);
    output_expect(ipts, 0) = vx;
  }
  //StringFunction sf2(sf1.getFunctionString().c_str(), Name("sf2"), Dimensions(NPTS, 4), Dimensions(NPTS, 1));
  StringFunction sf2(sf1.getFunctionString().c_str(), Name("sf2"), Dimensions( 3), Dimensions( 1));
  sf2(points, output, 0.0);
  for (unsigned ipts = 0; ipts < NPTS; ipts++)
  {
    STKUNIT_EXPECT_DOUBLE_EQ(output(ipts, 0), output_expect(ipts, 0));
  }
  /// indirection
  StringFunction sf2_1("sf2", Name("sf2_1"), Dimensions( 3), Dimensions( 1));
  sf2_1(points, output, 0.0);
  for (unsigned ipts = 0; ipts < NPTS; ipts++)
  {
    STKUNIT_EXPECT_DOUBLE_EQ(output(ipts, 0), output_expect(ipts, 0));
  }
}
void test_copies_of_shared_future_become_ready_together()
{
    boost::packaged_task<int> pt(make_int);
    boost::unique_future<int> fi=pt.get_future();

    boost::shared_future<int> sf(::cast_to_rval(fi));
    boost::shared_future<int> sf2(sf);
    boost::shared_future<int> sf3;
    sf3=sf;
    BOOST_CHECK(sf.get_state()==boost::future_state::waiting);
    BOOST_CHECK(sf2.get_state()==boost::future_state::waiting);
    BOOST_CHECK(sf3.get_state()==boost::future_state::waiting);

    pt();

    int i=0;
    BOOST_CHECK(sf.is_ready());
    BOOST_CHECK(sf.has_value());
    BOOST_CHECK(!sf.has_exception());
    BOOST_CHECK(sf.get_state()==boost::future_state::ready);
    BOOST_CHECK(i=sf.get());
    BOOST_CHECK(i==42);
    i=0;
    BOOST_CHECK(sf2.is_ready());
    BOOST_CHECK(sf2.has_value());
    BOOST_CHECK(!sf2.has_exception());
    BOOST_CHECK(sf2.get_state()==boost::future_state::ready);
    BOOST_CHECK(i=sf2.get());
    BOOST_CHECK(i==42);
    i=0;
    BOOST_CHECK(sf3.is_ready());
    BOOST_CHECK(sf3.has_value());
    BOOST_CHECK(!sf3.has_exception());
    BOOST_CHECK(sf3.get_state()==boost::future_state::ready);
    BOOST_CHECK(i=sf3.get());
    BOOST_CHECK(i==42);
}
示例#5
0
Status Operators::SMJ(const string& result,           // Output relation name
                      const int projCnt,              // Number of attributes in the projection
                      const AttrDesc attrDescArray[], // Projection list (as AttrDesc)
                      const AttrDesc& attrDesc1,      // The left attribute in the join predicate
                      const Operator op,              // Predicate operator
                      const AttrDesc& attrDesc2,      // The left attribute in the join predicate
                      const int reclen)               // The length of a tuple in the result relation
{
  cout << "Algorithm: SM Join" << endl;

  // Relation names
  string relation1 = attrDesc1.relName;
  string relation2 = attrDesc2.relName;

  // Determine num-bytes of individual record for each input relation
  // Relation 1
  int attrCnt1, attrCnt2, recLen1, recLen2;
  AttrDesc* attrs1, * attrs2, * end;
  Status status = attrCat->getRelInfo(relation1, attrCnt1, attrs1); 
  if (status != OK) {
    return status;
  } 
  recLen1 = 0;
  end = attrs1 + attrCnt1;
  while (attrs1 != end) {
    recLen1 += attrs1->attrLen;
    ++attrs1;
  }

  // Relation 2
  status = attrCat->getRelInfo(relation2, attrCnt2, attrs2); 
  if (status != OK) {
    return status;
  } 
  recLen2 = 0;
  end = attrs2 + attrCnt2;
  while (attrs2 != end) {
    recLen2 += attrs2->attrLen;
    ++attrs2;
  }
  
  // Calculate max num tuples for each input relation
  int mnr1 = 0.8 * bufMgr->numUnpinnedPages() * PAGESIZE / recLen1;
  int mnr2 = 0.8 * bufMgr->numUnpinnedPages() * PAGESIZE / recLen2;

  // Initialize sorted files
  // Relation 1
  SortedFile sf1(
    relation1,
    attrDesc1.attrOffset,
    attrDesc1.attrLen,
    (Datatype)attrDesc1.attrType,
    mnr1,
    status
  );
  if (status != OK) {
    return status;
  }
  // Relation 2
  SortedFile sf2(
    relation2,
    attrDesc2.attrOffset,
    attrDesc2.attrLen,
    (Datatype)attrDesc2.attrType,
    mnr2,
    status
  );
  if (status != OK) {
    return status;
  }

  // Initialize heap file for output relation
  HeapFile outputHf(result, status);
  if (status != OK) {
    return status;
  }

  Record rec1, rec2;
  
  //Initialize rec2
  status = sf2.next(rec2);
  if(status == FILEEOF)
  { return OK;
  }
  else if (status != OK)
  { return status;
  }
  
  while (1)
  {
    status = sf1.next(rec1);
    if (status == FILEEOF)
    { break;
    }
    else if (status != OK)
    { return status;
    }
    bool fileEnd = false;
    
    //Step through file 1 while rec2's attribute is greater than rec1's
    while (matchRec(rec1, rec2, attrDesc1, attrDesc2) < 0)
    {
      status = sf1.next(rec1);
      if(status == FILEEOF)
      { 
        fileEnd = true;
        break;
      }
      else if (status != OK)
      { return status;
      }
    }
    if(fileEnd)
    { break;
    }
    
    //Step through file 2 while rec1's attribute is greater than rec2's
    while (matchRec(rec1, rec2, attrDesc1, attrDesc2) > 0)
    {
      status = sf2.next(rec2);
      if(status == FILEEOF)
      { 
        fileEnd = true;
        break;
      }
      else if (status != OK)
      { return status;
      }
    }
    if(fileEnd)
    { break;
    }

    //Confirm that a match has been found. If not, restart the search process.
    if(matchRec(rec1, rec2, attrDesc1, attrDesc2) != 0)
    { continue;
    }
    
    //Found a join match, since neither attribute value is greater than the other
    sf2.setMark();
    while (matchRec(rec1, rec2, attrDesc1, attrDesc2) == 0)
    {
      // Join records 
      // Build join-record data with projected attributes
      char* joinRecData = new char[reclen];
      for (int adIdx = 0; adIdx < projCnt; ++adIdx) {
        // Determine from which to copy
        Record* inputRecord = strcmp(attrDescArray[adIdx].relName, attrDesc1.relName)
          ? &rec2
          : &rec1;
        
        // Copy data from input record to join record
        memcpy(
          joinRecData,
          (char*)inputRecord->data + attrDescArray[adIdx].attrOffset,
          attrDescArray[adIdx].attrLen
        );

        // Advance join record pointer
        joinRecData += attrDescArray[adIdx].attrLen;
      }
      
      // Insert join record into result heap file
      joinRecData -= reclen;
      Record joinRec = {joinRecData, reclen};
      RID outputRid;
      status = outputHf.insertRecord(joinRec, outputRid);
      if (status != OK) {
        return status;
      }
      
      //step through file 2 as long as a match exists
      status = sf2.next(rec2);
      if(status == FILEEOF)
      { break;
      }
      else if (status != OK)
      { return status;
      }
    }
    
    //Go back to the start of the matching record interval in file 2,
    //to check for possible duplicate values in file 1.
    sf2.gotoMark();
    status = sf2.next(rec2);
    if(status == FILEEOF)
    { break;
    }
    else if (status != OK)
    { return status;
    }
    
  }
  
  return OK;
}
示例#6
0
文件: ddmgr.cpp 项目: aolko/construct
///////////////////////////////////////////////////
//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
}