Exemplo n.º 1
0
HRESULT CFolderViewCommandProvider::s_OnNewFolder(IShellItemArray * /* psiItemArray */, IUnknown * /* pv */)
{
	DataProvider dataProvider;
	dataProvider.logInfo("Create new folder");
	//SendMessage(pici->hwnd, 0x111, 0x7103, 0);
	return S_OK;
}
Exemplo n.º 2
0
 void CameraBuffer::execute(DataProvider& provider)
 {
     // get the input data
     Id2DataPair inputMapper(INPUT);
     provider.receiveInputData(inputMapper);
     
     // try to get a free buffer
     Data* buffer = 0;
     try
     {
         buffer = m_buffers(0);
     }
     catch(Timeout&)
     {
     }
     
     if(buffer)
     {
         // there was a free buffer
         DataContainer bufferContainer(buffer);
         
         // remember it in the recycling access
         m_buffers.add(bufferContainer);
         
         Id2DataPair outputMapper(OUTPUT, inputMapper.data());
         Id2DataPair bufferMapper(BUFFER, bufferContainer);
         Id2DataPair idMapper(INDEX, DataContainer(new UInt32(m_id)));
         
         // send it to the output (together with the input image and the current index)
         provider.sendOutputData(outputMapper && bufferMapper && idMapper);
     }
     
     // increase the index
     ++m_id;
 }
Exemplo n.º 3
0
int main()
{

	GenericObjectFactory<int, BaseFigure> figureFactory;
	figureFactory.add<Square>((int)FigureTypes::square);
	figureFactory.add<Circle>((int)FigureTypes::circle);
	figureFactory.add<Arc>((int)FigureTypes::anc);
	figureFactory.add<Polygon_Line>((int)FigureTypes::polygon_line);
	figureFactory.add<Polygon>((int)FigureTypes::polygon);


	DataProvider provider;
	WDraw drawer;
	try {
		int objects_num = provider.rdInt();

		for (int i = 0; i < objects_num; ++i) {
			int id = provider.rdInt();
			BaseFigure *figure = figureFactory.get(id)();
			std::cout << int(figure->type()) << std::endl;
			figure->read(provider);
			figure->draw(drawer);
		}

		provider.rdDouble();
	}
	catch (ReadError) {
		std::cerr << "Reading error." << std::endl;
	}
	catch (EndOfFile) {
		std::cerr << "End of file reached." << std::endl;
	}

	system("pause");
}
void Rnn::generate(DataProvider& dp) {
  int wordId = 0;
  std::string word;
  dp.randomWord(wordId, word);
  std::cout << word << " ";

  Vector Htm1(firstWordHidden_);
  Vector htm1P(firstCharHidden_);

  for (int i=0; i<20; i++) {
    word = generator_.generate(wordId, Htm1, htm1P);
    word.pop_back(); // removing the underscore

    Htm1.copy(generator_.Ht_);
    htm1P.copy(generator_.hp_[generator_.lastChar - 1]);

    wordId = dp.getWordId(word);
    if (wordId != 0) {
      std::cout << "#" << word << " ";
    } else {
      std::cout << word << " ";
    }
  }
  std::cout << std::endl;
}
Exemplo n.º 5
0
void Polygon::read(DataProvider &provider) {
	points.clear();
	int params_num = provider.rdInt();
	for (int i = 0; i < params_num / 2; ++i) {
		double x = provider.rdDouble(),
			y = provider.rdDouble();
		points.push_back(Point2d(x, y));
	}
}
Exemplo n.º 6
0
 void ExceptionOperator::execute(DataProvider& provider)
 {
     Id2DataPair input(INPUT);
     
     provider.receiveInputData(input);
     
     provider.sleep(100);
     
     if(m_throwExecute)
         throw OperatorError(*this, "Failed to execute operator.");
 }
Exemplo n.º 7
0
static ssize_t
data_read_callback(void *opaque, void *buf, size_t buflen)
{
    DataProvider *provider = static_cast<DataProvider *>(opaque);
    if(!provider)
    {
        errno = EINVAL;
        return -1;
    }
    return provider->read(buf, buflen);
}
Exemplo n.º 8
0
void StationScheduleModel::fetch(const QString &name, const QString &code)
{
    DataProvider *provider = DataProvider::instance();

    if (!error().isEmpty())
        setError(QString());
    m_departureSchedules.clear();
    m_arrivalSchedules.clear();
    provider->fetchStationSchedule(name, code);
    setName(name);
    setCode(code);
}
Exemplo n.º 9
0
 void ParameterOperator::execute(DataProvider& provider)
 {
     Id2DataPair input1(INPUT_1);
     Id2DataPair input2(INPUT_2);
     
     provider.receiveInputData(input1 && input2);
     
     // execute...
     
     Id2DataPair output1(OUTPUT_1, input1.data());
     Id2DataPair output2(OUTPUT_2, input2.data());
     provider.sendOutputData(output1 && output2);
 }
Exemplo n.º 10
0
 void ReadDirectory::execute(DataProvider& provider)
 {
     if (m_files.size() == 0)
         throw OperatorError(*this, "Directory is empty.");
         
     Data* data = 0;
     std::size_t index = m_currentIndex;
     do
     {
         boost::filesystem::path file(m_files[index]);
         index = (index + 1) % m_files.size();
         std::string ext = file.extension().string();
         std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
         if (ext == ".png" || ext == ".jpg" || ext == ".jpeg")
         {
             data = new cvsupport::Image(file.string());
         }
     }
     while (data == 0 && index != m_currentIndex);
     
     m_currentIndex = index;
     
     if (data == 0)
         throw OperatorError(*this, "Found no usable file in selected directory.");
     
     DataContainer container(data);
     Id2DataPair outputDataMapper(OUTPUT, container);
     provider.sendOutputData(outputDataMapper);
 }
Exemplo n.º 11
0
 void Send::execute(DataProvider& provider)
 {
     Id2DataPair inputMapper(INPUT);
     provider.receiveInputData(inputMapper);
     
     m_server->send(inputMapper.data());
 }
Exemplo n.º 12
0
static off_t
data_seek_callback(void *opaque, off_t offset, int whence)
{
    DataProvider *provider = static_cast<DataProvider *>(opaque);
    if(!provider)
    {
        errno = EINVAL;
        return -1;
    }
    if(whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END)
    {
        errno = EINVAL;
        return -1;
    }
    return provider->seek(offset, whence);
}
void Rnn::train(DataProvider& dp,
                bool doTrain,
                double& seconds,
                double& wordEntropy,
                double& charEntropy,
                int& nChars) {
  dp.initIterator();
  int nWords = dp.getNumTokens();
  wordEntropy = 0.0;
  charEntropy = 0.0;
  double loss = 0.0;
  nChars = 0;
  int now = 0;
  int next = 0;
  std::string nextWord;
  auto tic = std::chrono::steady_clock::now();
  auto toc = std::chrono::steady_clock::now();
  seconds = 0.0;
  for (int i=0; i<nWords; i++) {
    if ( i%10000 == 0 && i>0 ) {
      toc = std::chrono::steady_clock::now();
      seconds = std::chrono::duration_cast<std::chrono::milliseconds>
          (toc - tic).count() / 1000.0;
      if (VERBOSE) {
        printf("train=%d token %8d/%8d ", doTrain, i, nWords);
        printf("char-entropy=%12.6e ", charEntropy / nChars);
        printf("word-entropy=%12.6e ", charEntropy / i);
        printf("word-model-entropy=%12.6e ", wordEntropy / i);
        printf("loss=%12.6e ", loss);
        printf("time=%-8.0f ", seconds);
        printf("sec/epoch=%-8.0f ", seconds / i * nWords);
        printf("words/sec=%-8.0f ", i / seconds);
        printf("chars/sec=%-8.0f ", nChars / seconds);
        std::cout << std::endl;
        if (doTrain) {
          // generate(dp);
        }
      }
    }
    dp.getToken(now, next, nextWord);
    forward(now, next, nextWord, doTrain, wordEntropy, charEntropy, nChars);
    loss = model_.alpha_ * wordEntropy + (1.0 - model_.alpha_) * charEntropy;
  }
}
Exemplo n.º 14
0
 void Merge::execute(DataProvider& provider)
 {
     if (m_list == 0)
     {
         Id2DataPair dataMapper(INPUT_NUM_ITEMS);
         provider.receiveInputData(dataMapper);
         ReadAccess access(dataMapper.data());
         
         try
         {
             m_numItems = toInt(access.get());
         }
         catch (BadCast&)
         {
             throw InputError(INPUT_NUM_ITEMS, *this, "Number of items must be an integer.");
         }
         
         m_list = new List();
     }
     
     if (m_list->content().size() < m_numItems)
     {
         RecycleAccess recycler;
         {
             Id2DataPair dataMapper(INPUT_DATA);
             provider.receiveInputData(dataMapper);
             recycler.add(dataMapper.data());
         }
         
         Data* data = recycler.get();
         m_list->content().push_back(data);
     }
     
     if (m_list->content().size() == m_numItems)
     {
         DataContainer out(m_list);
         m_list = 0;
         m_numItems = 0;
         Id2DataPair dataMapper(OUTPUT, out);
         
         provider.sendOutputData(dataMapper);
     }
 }
Exemplo n.º 15
0
 void TestOperator::execute(DataProvider& provider)
 {
     if(m_throwException)
     {
         throw InternalError("Funny exception.");
     }
         
     Id2DataPair input1(INPUT_1);
     Id2DataPair input2(INPUT_2);
     
     provider.receiveInputData(input1 && input2);
     
      // execute...
     m_numExecutes++;
     boost::this_thread::sleep_for(boost::chrono::milliseconds(m_sleepTime));
     
     Id2DataPair output1(OUTPUT_1, input1.data());
     Id2DataPair output2(OUTPUT_2, input2.data());
     provider.sendOutputData(output1 && output2);
 }
Exemplo n.º 16
0
 void Split::execute(DataProvider& provider)
 {
     if (m_storedItems.size() == 0)
     {
         RecycleAccess recycle;
         {
             Id2DataPair input(INPUT);
             provider.receiveInputData(input);
             recycle.add(input.data());
         }
         Data* data = recycle.get();
         List* list = data_cast<List>(data);
         
         if (list == 0)
             throw InputError(INPUT, *this, "Input data must be a 'List' object.");
         
         for (std::vector<Data*>::iterator iter = list->content().begin();
              iter != list->content().end(); ++iter)
         {
             m_storedItems.push_back(DataContainer(*iter));
         }
         
         uint64_t size = list->content().size();
         list->content().clear();
         delete list;
         
         DataContainer outNumItems(new UInt64(size));
         Id2DataPair dataMapper(OUTPUT_NUM_ITEMS, outNumItems);
         
         provider.sendOutputData(dataMapper);
     }
     
     if (m_storedItems.size() != 0)
     {
         DataContainer outData = m_storedItems.front();
         Id2DataPair dataMapper(OUTPUT_DATA, outData);
         m_storedItems.pop_front();
         
         provider.sendOutputData(dataMapper);
     }
 }
//! [0]
MapViewDemo::MapViewDemo(bb::cascades::Application *app)
    : QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("_mapViewTest", this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    QObject* mapViewAsQObject = root->findChild<QObject*>(QString("mapViewObj"));
    if (mapViewAsQObject) {
        mapView = qobject_cast<bb::cascades::maps::MapView*>(mapViewAsQObject);
        mapView->setCaptionGoButtonVisible(true);
        if (mapView) {
            // creating a data provider just for the device location object. that way, when the clear function is call, this object is not removed.
            DataProvider* deviceLocDataProv = new DataProvider("device-location-data-provider");
            mapView->mapData()->addProvider(deviceLocDataProv);

            // create a geolocation just for the device's location
            deviceLocation = new GeoLocation("device-location-id");
            deviceLocation->setName("Current Device Location");
            deviceLocation->setDescription("<html><a href=\"http://www.blackberry.com\">Hyperlinks</a> are super useful in bubbles.</html>");

            // for that location, replace the standard default pin with the provided bulls eye asset
            Marker bullseye = Marker(UIToolkitSupport::absolutePathFromUrl(
                                QUrl("asset:///images/me.png")), QSize(60, 60),
                                QPoint(29, 29), QPoint(29, 1));
            deviceLocation->setMarker(bullseye);

            deviceLocDataProv->add(deviceLocation);
        }
    }

    // set created root object as a scene
    app->setScene(root);
}
Exemplo n.º 18
0
 void ReadGpio::execute(DataProvider& provider)
 {
     int value = impl::GPIORead(static_cast<int>(m_gpio));
     
     if (-1 == value)
     {
         throw OperatorError(*this, 
             (boost::format("Failed to read from GPIO %1%.") % m_gpio).str());
     }
     
     DataContainer data(new Bool(value));
     Id2DataPair output(OUTPUT, data);
     provider.sendOutputData(output);
 }
Exemplo n.º 19
0
 void WriteGpio::execute(DataProvider& provider)
 {
     runtime::Id2DataPair input(INPUT);
     provider.receiveInputData(input);
     
     runtime::ReadAccess access(input.data());
     int value = access.get<runtime::Bool>();
     
     if (impl::GPIOWrite(static_cast<int>(m_gpio), value))
     {
         throw OperatorError(*this, 
             (boost::format("Failed to write to GPIO %1%.") % m_gpio).str());
     }
 }
Exemplo n.º 20
0
 void Flicker::execute(DataProvider& provider)
 {
     Id2DataPair inputDataMapper(INPUT);
     provider.receiveInputData(inputDataMapper);
     
     DataContainer container = inputDataMapper.data();
     WriteAccess access(container);
     runtime::Image& image = access.get<runtime::Image>();
     
     switch(image.depth())
     {
     case 1:
         applyFlicker<uint8_t>(m_amount, image);
         break;
     case 2:
         applyFlicker<uint16_t>(m_amount, image);
         break;
     default:
         throw WrongInputType(INPUT, *this);
     }
     
     Id2DataPair outputDataMapper(OUTPUT, container);
     provider.sendOutputData( outputDataMapper);
 }
Exemplo n.º 21
0
 void ConstData::execute(DataProvider& provider)
 {
     if (! valuePtr())
         throw InternalError("Value has not been set");
     
     DataContainer data;
     if (m_allocateData)
     {
         data = DataContainer(valuePtr()->clone());
     }
     else
     {
         Data* dataPtr = 0;
         
         if (m_recycleAccess.empty())
         {
             // if this is the first time the operator executes the value must
             // be cloned
             dataPtr = valuePtr()->clone();
         }
         else 
         {         
             // otherwise the value in the recycler can be reused              
             dataPtr = m_recycleAccess.get();
         }
             
         if (dataPtr != valuePtr())
         {
             // if the value was changed by the user since the last execution
             // update it
             delete dataPtr;
             dataPtr = valuePtr()->clone();
         }
         
         // send and remember for the next execution
         data = DataContainer(dataPtr);
         m_recycleAccess.add(data);
     }
     
     Id2DataPair outputDataMapper(OUTPUT, data);
     provider.sendOutputData( outputDataMapper);
 }
Exemplo n.º 22
0
 void ConvertPixelType::execute(DataProvider& provider)
 {
     if (m_dataFlow == MANUAL)
     {
         Id2DataPair srcMapper(SOURCE);
         Id2DataPair destMapper(DESTINATION);
         provider.receiveInputData(srcMapper && destMapper);
         
         if(srcMapper.data() == destMapper.data())
             throw InputError(DESTINATION, *this, "Destination image must not be the same image as the source image."); 
         
         ReadAccess src(srcMapper.data());
         WriteAccess dest(destMapper.data());
         
         const runtime::Image& srcImage = src.get<runtime::Image>();
         runtime::Image& destImage = dest.get<runtime::Image>();
         
         runtime::Image::PixelType pixelType = runtime::Image::PixelType((unsigned int)(m_pixelType));
         
         unsigned int destImageSize = srcImage.width() * srcImage.height() * getDestPixelSize(pixelType);
         unsigned int destImageStride = srcImage.width() * getDestPixelSize(pixelType);
         
         if(destImage.bufferSize() < destImageSize)
             throw InputError(DESTINATION, *this, "Destination image is too small.");
         
         destImage.initializeImage(srcImage.width(), srcImage.height(), destImageStride, destImage.buffer(), pixelType);
         
         if((srcImage.pixelType() == runtime::Image::RGB_24 || srcImage.pixelType() == runtime::Image::BGR_24)
         && (pixelType == runtime::Image::BAYERBG_8 || pixelType == runtime::Image::BAYERGB_8))
         {
             // this case is not handled by OpenCV
             rgbToBayer(srcImage, destImage);
         }
         else
         {
             // use OpenCV for conversion
             openCvConversion(srcImage, destImage);
         }
         
         Id2DataPair outputMapper(OUTPUT, destMapper.data());
         provider.sendOutputData( outputMapper);
     }
     else // allocate destination data on the fly
     {
         Id2DataPair srcMapper(SOURCE);
         provider.receiveInputData(srcMapper);
         
         ReadAccess src(srcMapper.data());
         
         const runtime::Image& srcImage = src.get<runtime::Image>();
         
         runtime::Image::PixelType pixelType = runtime::Image::PixelType((unsigned int)(m_pixelType));
         
         runtime::Image* destImage = new cvsupport::Image(srcImage.width(), srcImage.height(), pixelType);
         DataContainer destContainer(destImage);
         
         if((srcImage.pixelType() == runtime::Image::RGB_24 || srcImage.pixelType() == runtime::Image::BGR_24)
         && (pixelType == runtime::Image::BAYERBG_8 || pixelType == runtime::Image::BAYERGB_8))
         {
             // this case is not handled by OpenCV
             rgbToBayer(srcImage, *destImage);
         }
         else
         {
             // use OpenCV for conversion
             openCvConversion(srcImage, *destImage);
         }
         
         Id2DataPair outputMapper(OUTPUT, destContainer);
         provider.sendOutputData( outputMapper);
     }
 }
Exemplo n.º 23
0
static void data_release_callback(void *opaque)
{
    DataProvider *provider = static_cast<DataProvider *>(opaque);
    if(provider)
        provider->release();
}