Exemple #1
0
/**
 * アニメーションを読み込む
 */
void loadAnimation(ANIME_SET* graphic,ARCHIVE* archive,const char* file_name){
	BUF* gfx_file = getFile(archive,file_name);
	//ヘッダを飛ばす。
	seekBuf(gfx_file,(long)strlen(ANIME_HEADER),SEEK_SET);
	//ファイル名取得
	int filename_size;
	readBuf(gfx_file,&filename_size,sizeof(filename_size));
	graphic->filename_size = filename_size;
	graphic->filename = malloc(filename_size+1);
	readBuf(gfx_file,graphic->filename,filename_size);
	graphic->filename[filename_size] = '\0';
	//スプライト取得
	SDL_RWops* frame_ops = getGraphixFile(archive,graphic->filename);
	getSpriteFromOPS(&graphic->sprite,frame_ops);
	frame_ops->close(frame_ops);					//メモリ開放は忘れずに
	//スプライトエリア用スプライト
	SPRITE* anime_sprite = &graphic->sprite;
	//モード、フラグ、アニメ数。
	readBuf(gfx_file,&graphic->mode,sizeof(graphic->mode));
	readBuf(gfx_file,&graphic->flag,sizeof(graphic->flag));
	readBuf(gfx_file,&graphic->anime_num,sizeof(graphic->anime_num));
	int anime_num = graphic->anime_num;
	graphic->anime = malloc( sizeof(ANIMATION*) * anime_num );
	int i=0;
	for(;i<anime_num;i++){
		//アニメ番号
		int num = 0;
		readBuf(gfx_file,&num,sizeof(num));
		if(anime_num < num) raiseError("invalid animation file:",file_name);
		//メモリ確保。
		graphic->anime[num] = malloc(sizeof(ANIMATION));
		ANIMATION* anime = graphic->anime[num];
		anime->num = num;
		//フレーム番号取得
		int frame_num;
		readBuf(gfx_file,&frame_num,sizeof(frame_num));
		anime->frame_num = frame_num;
		anime->frame = malloc(sizeof(ANIMATION_FRAME)*frame_num);
		int j;
		for(j=0;i<frame_num;j++){
			//フレームへのポインタの設定
			ANIMATION_FRAME* frame = &anime->frame[j];
			//持続時間
			readBuf(gfx_file,&frame->frame_time,sizeof(frame->frame_time));
			//スプライトの設定
			frame->sprite_area.sprite = anime_sprite;
			readBuf(gfx_file,&frame->sprite_area.x,sizeof(frame->sprite_area.x));
			readBuf(gfx_file,&frame->sprite_area.y,sizeof(frame->sprite_area.y));
			readBuf(gfx_file,&frame->sprite_area.width,sizeof(frame->sprite_area.width));
			readBuf(gfx_file,&frame->sprite_area.height,sizeof(frame->sprite_area.height));
		}
	}
	deleteBuf(gfx_file);
}
void c_init_serial(
  TermPair *termStorage, const char *devicePath, 
  const int speed, const Bool hw_flow_control
) {
  if (termStorage == NULL) {
    raiseError("The storage for the file descriptor must not be NULL");
  }

  termStorage->fd = open(devicePath, O_RDWR|O_NONBLOCK);
  c_init_serialFD(termStorage, speed, hw_flow_control);
}
Exemple #3
0
    /* "warning" assert -- safe to continue, so we don't throw exception. */
    void wasserted(const char *msg, const char *file, unsigned line) {
        problem() << "warning Assertion failure " << msg << ' ' << file << ' ' << dec << line << endl;
        sayDbContext();
        raiseError(0,msg && *msg ? msg : "wassertion failure");
        assertionCount.condrollover( ++assertionCount.warning );
#if defined(_DEBUG) || defined(_DURABLEDEFAULTON)
        // this is so we notice in buildbot
        log() << "\n\n***aborting after wassert() failure in a debug/test build\n\n" << endl;
        abort();
#endif
    }
Exemple #4
0
static PyObject *isOptionSettable (PyObject * self, PyObject * args)
{
    SANE_Int cap;
    long lg;

    if (!PyArg_ParseTuple (args, "l", &lg))
        raiseError("Invalid arguments");

    cap = lg;
    return PyInt_FromLong (SANE_OPTION_IS_SETTABLE (cap));
}
Exemple #5
0
void GdbResponseWriter::WriteData(GdbResponse const& input)
{
    if (fromUser.HasData())
        raiseError(ConcurrencyError("GdbResponseWriter detected new user command came in before response to last command could be printed."));

    if (input.prompt)
        last_prompt = *input.prompt;

    string result = Write(input.values);
    sink.WriteData({result, last_prompt});
}
void XSchemaSequence::scanForAttributes(QDomAttr &attribute, void * /*context*/)
{
    QString name = attribute.nodeName();

    if(name == IO_GENERIC_ID) {
        _id = attribute.value() ;
    } else if(name == IO_GENERIC_MINOCCURS) {
        if(!_minOccurs.setValueFromAttribute(attribute.value())) {
            raiseError(this, attribute, false);
        }
    } else if(name == IO_GENERIC_MAXOCCURS) {
        if(!_maxOccurs.setValueFromAttribute(attribute.value())) {
            raiseError(this, attribute, false);
        }
    } else {
        if(!readOtherAttributes(attribute)) {
            raiseError(this, attribute, false);
        }
    }
}
Exemple #7
0
 void asserted(const char *msg, const char *file, unsigned line) {
     problem() << "Assertion failure " << msg << ' ' << file << ' ' << dec << line << endl;
     sayDbContext();
     raiseError(msg && *msg ? msg : "assertion failure");
     lastAssert[0].set(msg, getDbContext().c_str(), file, line);
     stringstream temp;
     temp << "assertion " << file << ":" << line;
     AssertionException e;
     e.msg = temp.str();
     throw e;
 }
PClassifier TLogRegLearner::operator()(PExampleGenerator gen, const int &weight)
{ 
  int error;
  PVariable var;
  PClassifier cl = fitModel(gen, weight, error, var);

  if (error >= TLogRegFitter::Constant)
    raiseError("%s in %s", error==TLogRegFitter::Constant ? "constant" : "singularity", var->get_name().c_str());

  return cl;
}
Exemple #9
0
void QxThreadPool::runServer()
{
   QxServer server(this);
   server.setMaxPendingConnections(QxConnect::getSingleton()->getThreadCount());
   quint16 serverPort = (quint16)(QxConnect::getSingleton()->getPort());
   if (! server.listen(QHostAddress::Any, serverPort))
   { raiseError(QString("[QxOrm] cannot run server : '") + server.errorString() + QString("'"), QxTransaction_ptr()); return; }
   Q_EMIT serverIsRunning(true, (& server));
   exec();
   Q_EMIT serverIsRunning(false, NULL);
}
/**
 * アニメーションを読み込む
 */
void loadAnimation(ANIME_SET* graphic,ARCHIVE* archive,const char* file_name){
	SDL_RWops* gfx_file = getFile(archive,file_name);
	//ヘッダを飛ばす。
	SDL_RWseek(gfx_file,(long)strlen(ANIME_HEADER),SEEK_SET);
	//ファイル名取得
	int filename_size;
	SDL_RWread(gfx_file,&filename_size,sizeof(filename_size),1);
	graphic->filename_size = filename_size;
	graphic->filename = malloc(filename_size+1);
	SDL_RWread(gfx_file,graphic->filename,filename_size,1);
	graphic->filename[filename_size] = '\0';
	//モード、フラグ、アニメ数、アルファブレンディング
	SDL_RWread(gfx_file,&graphic->mode,sizeof(graphic->mode),1);
	SDL_RWread(gfx_file,&graphic->flag,sizeof(graphic->flag),1);
	SDL_RWread(gfx_file,&graphic->anime_num,sizeof(graphic->anime_num),1);
	SDL_RWread(gfx_file,&graphic->is_alpha_blending,sizeof(graphic->is_alpha_blending),1);
	//スプライト取得
	getSpriteFromArchive(&graphic->sprite,archive,graphic->filename,graphic->is_alpha_blending,TRUE);
	//スプライトエリア用スプライト
	SPRITE* anime_sprite = &graphic->sprite;
	int anime_num = graphic->anime_num;
	graphic->anime = malloc( sizeof(ANIMATION*) * anime_num );
	int i=0;
	for(;i<anime_num;i++){
		//アニメ番号
		int num = 0;
		SDL_RWread(gfx_file,&num,sizeof(num),1);
		if(anime_num < num) raiseError("invalid animation file:",file_name);
		//メモリ確保。
		graphic->anime[num] = malloc(sizeof(ANIMATION));
		ANIMATION* anime = graphic->anime[num];
		anime->num = num;
		//フレーム番号取得
		int frame_num;
		SDL_RWread(gfx_file,&frame_num,sizeof(frame_num),1);
		anime->frame_num = frame_num;
		anime->frame = malloc(sizeof(ANIMATION_FRAME)*frame_num);
		int j;
		for(j=0;i<frame_num;j++){
			//フレームへのポインタの設定
			ANIMATION_FRAME* frame = &anime->frame[j];
			//持続時間
			SDL_RWread(gfx_file,&frame->frame_time,sizeof(frame->frame_time),1);
			//スプライトの設定
			int x,y,w,h;
			SDL_RWread(gfx_file,&x,sizeof(x),1);
			SDL_RWread(gfx_file,&y,sizeof(y),1);
			SDL_RWread(gfx_file,&w,sizeof(w),1);
			SDL_RWread(gfx_file,&h,sizeof(h),1);
			makeSpriteArea(&frame->sprite_area,anime_sprite,x,y,w,h);
		}
	}
	SDL_RWclose(gfx_file);
}
Exemple #11
0
CACMWaveFormat::CACMWaveFormat(WORD fmt, DWORD sz)
{
	MMRESULT mmr;

	m_fmt = NULL;
	m_size = 0;

	if (0 == sz)
	{
		CACMStruct<ACMFORMATTAGDETAILS>  tagD;

		// WIN95 bug keeps us from using the correct fmt here,
		// because acmFormatEnum fails later if not
		tagD->dwFormatTag = WAVE_FORMAT_UNKNOWN;
		mmr = acmFormatTagDetails(NULL, 
							tagD,
						ACM_FORMATTAGDETAILSF_LARGESTSIZE
						);

		if (0 != mmr)
			raiseError(mmr, 
			"Error getting format descriptor size");
		
		sz = tagD->cbFormatSize;

		
	}
	m_fmt = (LPWAVEFORMATEX) 
		   GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, sz);
			   
	if (m_fmt)
	{
		m_fmt->wFormatTag = fmt;
		m_size = sz;
	}
	else
	{
		raiseError(MMSYSERR_NOMEM, 
			"No memory for wave format descriptor");
	}
}
void QHelpProjectDataPrivate::readProject()
{
    while (!atEnd()) {
        readNext();
        if (isStartElement()) {
            if (name() == QLatin1String("virtualFolder")) {
                virtualFolder = readElementText();
                if (!hasValidSyntax(QLatin1String("test"), virtualFolder))
                    raiseError(QCoreApplication::translate("QHelpProject",
                                   "Virtual folder has invalid syntax in file: \"%1\"").arg(fileName));
            } else if (name() == QLatin1String("namespace")) {
                namespaceName = readElementText();
                if (!hasValidSyntax(namespaceName, QLatin1String("test")))
                    raiseError(QCoreApplication::translate("QHelpProject",
                                   "Namespace \"%1\" has invalid syntax in file: \"%2\"").arg(namespaceName, fileName));
            } else if (name() == QLatin1String("customFilter")) {
                readCustomFilter();
            } else if (name() == QLatin1String("filterSection")) {
                readFilterSection();
            } else if (name() == QLatin1String("metaData")) {
                QString n = attributes().value(QLatin1String("name")).toString();
                if (!metaData.contains(n))
                    metaData[n]
                        = attributes().value(QLatin1String("value")).toString();
                else
                    metaData.insert(n, attributes().
                                    value(QLatin1String("value")).toString());
            } else {
                raiseUnknownTokenError();
            }
        } else if (isEndElement() && name() == QLatin1String("QtHelpProject")) {
            if (namespaceName.isEmpty())
                raiseError(QCoreApplication::translate("QHelpProject",
                              "Missing namespace in QtHelpProject file: \"%1\"").arg(fileName));
            else if (virtualFolder.isEmpty())
                raiseError(QCoreApplication::translate("QHelpProject",
                               "Missing virtual folder in QtHelpProject file: \"%1\"").arg(fileName));
            break;
        }
    }
}
Exemple #13
0
static bool openXmlFile(QDomDocument &doc, const Utils::FileName &fileName)
{
    QFile f(fileName.toString());
    if (!f.open(QIODevice::ReadOnly))
        return false;

    if (!doc.setContent(f.readAll())) {
        raiseError(AndroidManager::tr("Cannot parse \"%1\".").arg(fileName.toUserOutput()));
        return false;
    }
    return true;
}
Exemple #14
0
static PyObject *cancelScan (_ScanDevice * self, PyObject * args)
{
    if (!PyArg_ParseTuple (args, ""))
        raiseError("Invalid arguments.");

    if (self->h == NULL)
        return raiseDeviceClosedError();

    sane_cancel (self->h);
    Py_INCREF (Py_None);
    return Py_None;
}
Exemple #15
0
bool	xbnode::getBool()
{
	if( isBool() )
		return (this->getText()=="true");
	if( isNumeric() )
		return getNumeric()!=0;
	if( isText() )
		return !getText().empty();

	raiseError( "getBool() cant convert", __FILE__,__LINE__);
	return false;
}
void QHelpProjectDataPrivate::readData(const QByteArray &contents)
{
    addData(contents);
    while (!atEnd()) {
        readNext();
        if (isStartElement()) {
            if (name() == QLatin1String("QtHelpProject")
                && attributes().value(QLatin1String("version")) == QLatin1String("1.0"))
                readProject();
            else
                raiseError(QCoreApplication::translate("QHelpProject",
                               "Unknown token. Expected \"QtHelpProject\"."));
        }
    }

    if (hasError()) {
        raiseError(QCoreApplication::translate("QHelpProject",
                       "Error in line %1: %2").arg(lineNumber())
            .arg(errorString()));
    }
}
Exemple #17
0
bool Crypto::testSha256()
{
    QByteArray sha256Test = CryptoHash::hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
                                             CryptoHash::Sha256);

    if (sha256Test != QByteArray::fromHex("248D6A61D20638B8E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1")) {
        raiseError("SHA-256 mismatch.");
        return false;
    }

    return true;
}
Exemple #18
0
void OpenCLFramework<T>::addInputBuffer(int argumentCounter, std::vector<T> input) {

	if (vectorSize != -1 && vectorSize != input.size())  {
		raiseError("You passed vectors with different lengths to the framework");
	}
	vectorSize = input.size();

	cl_mem inputBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, vectorSize * sizeof(T), (void *)&input[0], NULL);
	status = clSetKernelArg(kernel, argumentCounter, sizeof(cl_mem), (void *)&inputBuffer);
	checkError("clSetKernelArg input");
	inputBufferVector.push_back(inputBuffer);
}
Exemple #19
0
 void asserted(const char *msg, const char *file, unsigned line) {
     assertionCount.condrollover( ++assertionCount.regular );
     problem() << "Assertion failure " << msg << ' ' << file << ' ' << dec << line << endl;
     sayDbContext();
     raiseError(0,msg && *msg ? msg : "assertion failure");
     lastAssert[0].set(msg, getDbContext().c_str(), file, line);
     stringstream temp;
     temp << "assertion " << file << ":" << line;
     AssertionException e(temp.str(),0);
     breakpoint();
     throw e;
 }
/// Start the parsing of the plist. If it isn't a valid plist this method return false.
/// (it only checks and reads the existence of <plist>)
bool BasePListParser::beginParsing(QIODevice* device)
{
    lastErrorMessage_.clear();
    elementStack_.clear();

    xml_ = new QXmlStreamReader(device);
    if( readNextElement("plist" ) ) {
        return true;
    } else {
        raiseError( QObject::tr("Start element not found!"));
        return false;
    }
}
PClassifier
TSimpleTreeLearner::operator()(PExampleGenerator ogen, const int &weight)
{
	struct Example *examples, *ex;
	struct SimpleTreeNode *tree;
	struct Args args;
	int cls_vals;

	if (!ogen->domain->classVar)
		raiseError("class-less domain");

	if (!ogen->numberOfExamples() > 0)
	    raiseError("no examples");

	/* create a tabel with pointers to examples */
	ASSERT(examples = (struct Example *)calloc(ogen->numberOfExamples(), sizeof *examples));
	ex = examples;
	PEITERATE(ei, ogen) {
		ex->example = &(*ei);
		ex->weight = 1.0;
		ex++;
	}
Exemple #22
0
Object cuda_computeCapability(Object self, int nparts, int *argcv,
        Object *argv, int flags) {
    cuInit(0);
    int deviceCount = 0;
    cuDeviceGetCount(&deviceCount);
    if (deviceCount == 0) {
        raiseError("No CUDA devices found");
    }
    CUdevice cuDevice;
    int major, minor;
    cuDeviceComputeCapability(&major, &minor, cuDevice);
    return alloc_Float64(major + minor / 10.0);
}
Exemple #23
0
void ActivityLog::expect(ActivityLogLine test_log_entry, bool exact_match)
{
    string expected = test_log_entry.content;

    // Get the next result that is not part of the ignored labels.
    ActivityLogLine test_result;
    do
    {
        int counter = 0;
        while (!test_results.HasData())
        {
            boost::this_thread::sleep(boost::posix_time::milliseconds(5));
            if (++counter > 100)
            {
                //string msg = "Timed out waiting on next test result.";
                //string log_line = test_log_entry.label + ": " + expected;
                //cerr << msg << " expected " << log_line << endl;
                //throw boost::enable_current_exception(TestException(msg, log_line, ""));
            }
        }
        test_result = test_results.ReadData();
    }
    while   (test_plan.actionType(test_result) == TestActionType::ignore);

    if (test_result.label != test_log_entry.label)
    {
        cerr << "Did not get expected label, expected " << test_log_entry.label << " got " << test_result.label << endl;
        raiseError(TestException("Did not get expected label", test_log_entry.label, test_result.label));
    }
    else if (exact_match && test_result.content != test_log_entry.content)
    {
        string actual = test_result.content;

        print_error(expected, actual);

        raiseError(TestException("Did not get expected content", expected, actual));
    }
}
Exemple #24
0
int main()
{
    scanf ("%d%d%d%d", &N, &a, &b, &M);
    for (int u = 0; u < N; ++u)
        for (int v = 0; v < N; ++v)
            scanf("%d", &distance[u][v]);

    pingCount = 0;
    routeLength = 0;
    current = a;

    findRoute (N, a, b);

    if (current != b)
        raiseError ("Message has not reached its target");

    if (routeLength < distance[a-1][b-1] + 1)
        raiseError ("Unexpected: route is too short");

    printf ("OK\n");

    return 0;
}
Exemple #25
0
Object cuda_deviceName(Object self, int nparts, int *argcv,
        Object *argv, int flags) {
    cuInit(0);
    int deviceCount = 0;
    cuDeviceGetCount(&deviceCount);
    if (deviceCount == 0) {
        raiseError("No CUDA devices found");
    }
    CUdevice cuDevice;
    cuDeviceGet(&cuDevice, 0);
    char name[100];
    cuDeviceGetName(name, 100, cuDevice);
    return alloc_String(name);
}
Exemple #26
0
void Process::write(const std::string& s)
{
    ssize_t amt = 0;

    assert(selectpipe(pipes::WRITE_PIPE) != -1);

    amt = ::write(selectpipe(pipes::WRITE_PIPE), s.c_str(), s.size());

    // If we failed to write
    if (!(amt > 0 || (amt == 0 && s.empty())))
    {
        raiseError("Failed to write");
    }
}
void EasyOpenCL<T>::setOutputBuffer(uint argumentPosition) {

  // The program needs to know the length of the buffer - therefore, first pass
  // an input buffer so the length can be determined
  if (vectorSize == -1)  { raiseError("Please pass the input buffer first"); }

  // Create and append the actual output buffer
  cl_mem outputBuffer = clCreateBuffer(context, CL_MEM_READ_WRITE, vectorSize * sizeof(T), NULL, NULL);
  status = clSetKernelArg(kernel, argumentPosition, sizeof(cl_mem), (void *)&outputBuffer);
  checkError("clSetKernelArg outputBuffer " + std::to_string(argumentPosition));

  // Add the buffer to the map for later reference - retrieval and cleanup
  values[argumentPosition] = BoundValue<T>(outputBuffer);
}
Exemple #28
0
float TEFMDataDescription::getExampleWeight(const TExample &example) const
{ 
  if (example.domain != domain)
    raiseError("example's domain doesn't match the data descriptor's");

  float weight=1.0;
  TVarList::const_iterator vi(domain->attributes->begin()), vie(domain->attributes->end());
  TExample::iterator ei(example.begin());
  for(; vi!=vie; ei++, vi++)
    if ((*ei).isDK() && ((*ei).varType == TValue::INTVAR))
      weight /= (*vi)->noOfValues();

  return weight;
}
Exemple #29
0
bool TreatIterator::count( store::Item_t &result, PlanState &planState) const {
  bool const ret_val = theChild->count( result, planState );
  xs_integer const count( result->getIntegerValue() );

  switch ( theQuantifier ) {
    case SequenceType::QUANT_QUESTION:
      if ( count <= numeric_consts<xs_integer>::one() )
        break;
      // no break;
    case SequenceType::QUANT_ONE:
      if ( count > numeric_consts<xs_integer>::one() )
        raiseError("sequence of more than one item");
      // no break;
    case SequenceType::QUANT_PLUS:
      if ( count == numeric_consts<xs_integer>::zero() )
        raiseError("empty-sequence()");
      break;
    default:
      // do nothing
      break;
  }
  return ret_val;
}
Exemple #30
0
void CACMStream::Unprepare()
{
	m_mmr = 0;
	if (m_hdr->fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED)
	{
		m_hdr->cbSrcLength = m_hdr->dwSrcUser;
		m_mmr = acmStreamUnprepareHeader(m_strm, m_hdr, 0);
		GlobalFree(m_hdr->pbDst);
	}

	if (m_mmr)
		raiseError(m_mmr, 
			"Error unpreparing stream header");
}