Ejemplo n.º 1
0
    T* ClsTypeManager<T>::createByLabel(string _strLabel)
    {
	// getTypeName exceptions passed onto caller.
	string strType = label2type(_strLabel);

	T* pNewObject;
	try {
	    pNewObject = createObject(strType);
	}
	catch (iqrcommon::UnknownTypeError &e) {
	    throw UnknownTypeError(_strLabel);
	}

	return pNewObject;
    }
void onSignificantWifiChange(wifi_request_id id,
        unsigned num_results, wifi_significant_change_result **results) {
    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onSignificantWifiChange called, vm = %p, obj = %p, env = %p", mVM, mCls, env);

    jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult");
    if (clsScanResult == NULL) {
        ALOGE("Error in accessing class");
        return;
    }

    jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL);
    if (scanResults == NULL) {
        ALOGE("Error in allocating array");
        return;
    }

    for (unsigned i = 0; i < num_results; i++) {

        wifi_significant_change_result result = *(results[i]);

        jobject scanResult = createObject(env, "android/net/wifi/ScanResult");
        if (scanResult == NULL) {
            ALOGE("Error in creating scan result");
            return;
        }

        // setStringField(env, scanResult, "SSID", results[i].ssid);

        char bssid[32];
        sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result.bssid[0], result.bssid[1],
            result.bssid[2], result.bssid[3], result.bssid[4], result.bssid[5]);

        setStringField(env, scanResult, "BSSID", bssid);

        setIntField(env, scanResult, "level", result.rssi[0]);
        setIntField(env, scanResult, "frequency", result.channel);
        // setLongField(env, scanResult, "timestamp", result.ts);

        env->SetObjectArrayElement(scanResults, i, scanResult);
    }

    reportEvent(env, mCls, "onSignificantWifiChange", "(I[Landroid/net/wifi/ScanResult;)V",
        id, scanResults);

}
Ejemplo n.º 3
0
/**creates an quilateral traingle at given position and size**/
RenderObject Renderer::createRectangle(glm::vec3 origin, float length, float height, float size)
{

	float l = size * length / 2;
	float h = size * height / 2;
	return createObject (origin,	{	
									glm::vec3(origin.x - l, origin.y - h, origin.z),
									glm::vec3(origin.x - l, origin.y + h, origin.z),
									glm::vec3(origin.x + l, origin.y + h, origin.z),
									glm::vec3(origin.x + l, origin.y + h, origin.z),
									glm::vec3(origin.x + l, origin.y - h, origin.z),
									glm::vec3(origin.x - l, origin.y - h, origin.z) 
									}
						);
	
}
ossimObject* ossimContribImageSourceFactory::createObject(const ossimKeywordlist& kwl,
                                          const char* prefix)const
{
   const char* type = kwl.find(prefix, ossimKeywordNames::TYPE_KW);
   ossimObject* result = NULL;
   if(type)
   {
      result = createObject(ossimString(type));
      if(result)
      {
         result->loadState(kwl, prefix);
      }
   }

   return result;
}
Ejemplo n.º 5
0
void hsetCommand(caller_t *c)
{
    robj *o, *result;
    unsigned long update;

    if ((o = hashTypeLookupWriteElseCreate(c,c->argv[1])) == NULL) return;
    hashTypeTryConversion(o,c->argv,2,3);
    hashTypeTryObjectEncoding(o,&c->argv[2], &c->argv[3]);
    update = hashTypeSet(o,c->argv[2],c->argv[3]);
    update = update ? 0 : 1;
    result = createObject(REDIS_STRING, (void*)update);
    result->encoding = REDIS_ENCODING_INT;
    caller_set_err(c, ERR_NONE);
    caller_add_result(c, result);
    server.dirty++;
}
Ejemplo n.º 6
0
void Memory::resize(MemSize newSize)
{
    ObjectPtr* newMemory = new ObjectPtr[newSize];
    for (MemSize i = 0; i < (this->currentSize < newSize ? this->currentSize : newSize); i++)
    {
        newMemory[i] = this->memory[i];
    }

    for (MemSize i = this->currentSize; i < newSize; i++)
    {
        newMemory[i] = createObject();
    }

    this->currentSize = newSize;
    this->memory = newMemory;
}
Ejemplo n.º 7
0
static void runCmdInFakeClient(sds s) {
    //RL4 "runCmdInFakeClient: %s", s);
    int           argc;
    sds          *argv = sdssplitlen(s, sdslen(s), " ", 1, &argc); // FREEME 017
    if (!argv)    return;
    if (argc < 1) goto run_cmd_end;
    redisCommand *cmd  = lookupCommand(argv[0]);
    if (!cmd)     goto run_cmd_end;
    if ((cmd->arity > 0 && cmd->arity > argc) || (argc < -cmd->arity))
                  goto run_cmd_end;
    int    arity;
    robj **rargv;
    if (cmd->arity > 0 || cmd->proc == insertCommand    ||
                          cmd->proc == sqlSelectCommand ||
                          cmd->proc == tscanCommand)       {
        arity = abs(cmd->arity);
        rargv = zmalloc(sizeof(robj *) * arity);         /* ZFREE ME 018 */
        for (int j = 0; j < arity - 1; j++) {
            rargv[j] = createStringObject(argv[j], sdslen(argv[j])); // FREE 019
        }
        sds lastarg = sdsempty();
        for (int j = arity - 1; j < argc; j++) {
            if (j != (arity - 1)) lastarg = sdscatlen(lastarg, " ", 1);
            lastarg = sdscatlen(lastarg, argv[j], sdslen(argv[j]));
        }
        rargv[arity - 1] = createObject(REDIS_STRING, lastarg); // FREE 019
    } else {
        arity = argc;
        rargv = zmalloc(sizeof(robj *) * arity);         /* ZFREE ME 018 */
        for (int j = 0; j < arity; j++) {
            rargv[j] = createStringObject(argv[j], sdslen(argv[j])); // FREE 019
        }
    }
    redisClient *c  = CurrClient;
    redisClient *fc = rsql_createFakeClient();           /* DESTROY ME 020 */
    fc->argv        = rargv;
    fc->argc        = arity;
    fakeClientPipe(c, fc, NULL, 0, &NriFlag,
                   nonRelIndRespHandler, emptyNonRelIndRespHandler);
    rsql_freeFakeClient(fc);                             /* DESTROYED 020 */
    for (int j = 0; j < arity; j++) decrRefCount(rargv[j]); /* FREED 019 */
    zfree(rargv);                                        /* ZFREED 018 */

run_cmd_end:
    for (int j = 0; j < argc; j++) sdsfree(argv[j]);     /* FREED 017 */
    zfree(argv);                                         /* FREED 017 */
}
Ejemplo n.º 8
0
static Value createMethod(Context *ctx, const List<Value>& args)
{
    if (args.getCount() != 2)
    {
        ctx->throwException(createException(ExcType::ValueError, "__methodify takes 2 argument."));
    }

    Value result = createObject();

    HashMap<Str, Value>& resultMembers = ((ObjectData *)result.p)->members;

    resultMembers.set("__func__", createCopy(args[0]));
    resultMembers.set("__obj__", createCopy(args[1]));
    resultMembers.set("__call__", createNativeFunction(methodCall));

    return result;
}
Ejemplo n.º 9
0
// extern (used by Global.cpp)
void
boolean_class_init(as_object& where, const ObjectURI& uri)
{
    VM& vm = getVM(where);
    Global_as& gl = getGlobal(where);

    as_object* proto = createObject(gl);
    as_object* cl = vm.getNative(107, 2);
    cl->init_member(NSV::PROP_PROTOTYPE, proto);
    proto->init_member(NSV::PROP_CONSTRUCTOR, cl);

    attachBooleanInterface(*proto);
    
    // Register _global.Boolean
    where.init_member(uri, cl, as_object::DefaultFlags);

}
Ejemplo n.º 10
0
Actor* ObjectFactory::createActor(const std::string& path)
{
    if(Object* object = createObject(path))
    {
        if(Actor* actor = dynamic_cast<Actor*>(object))
        {
            return actor;
        }
        else
        {
            rLogErr(g_log, "[ObjectFactory] Given path \"" << path << "\" doesn`t describe an actor.");
            destroyObject(object);
        }
    }

    return nullptr;
}
Ejemplo n.º 11
0
/// This provides the prototype and static methods for TextField.
//
/// For SWF5 there is initially no prototype, for SWF6+ there is a 
/// limited prototype. This is changed later on instantiation of a
/// TextField.
void
textfield_class_init(as_object& where, const ObjectURI& uri)
{

    Global_as& gl = getGlobal(where);
    as_object* proto = createObject(gl);
    as_object* cl = gl.createClass(&textfield_ctor, proto);

    attachTextFieldInterface(*proto);
    attachTextFieldStaticMembers(*cl);
             
    where.init_member(uri, cl, as_object::DefaultFlags);

    // ASSetPropFlags is called on the TextField class.
    as_object* null = nullptr;
    callMethod(&gl, NSV::PROP_AS_SET_PROP_FLAGS, cl, null, 131);
}
Ejemplo n.º 12
0
int put(HashMap *map,void *key,void *value){
	List *listOfHashObjects;
	Object *objectPrevoiuslyPresent,*object;
	int hash;
	if(map == NULL || key == NULL) return 0;
	objectPrevoiuslyPresent = getMatchingObject(map,key,0);
	if(objectPrevoiuslyPresent){
		objectPrevoiuslyPresent->values = value;
		return 1;
	}
	object = createObject(key,value);
	hash = calculateHash(map,key);
	listOfHashObjects = get(map->buckets,hash);
	insert(listOfHashObjects,object,1);
	rehashIfNeeded(map);
	return 1;
};
Ejemplo n.º 13
0
void throw_tprotocolexception(char* what, long errorcode) {
    TSRMLS_FETCH();

    zval *zwhat, *zerrorcode;
    MAKE_STD_ZVAL(zwhat);
    MAKE_STD_ZVAL(zerrorcode);

    ZVAL_STRING(zwhat, what, 1);
    ZVAL_LONG(zerrorcode, errorcode);

    zval* ex;
    MAKE_STD_ZVAL(ex);
    createObject("TProtocolException", ex, 2, zwhat, zerrorcode);
    zval_ptr_dtor(&zwhat);
    zval_ptr_dtor(&zerrorcode);
    throw PHPExceptionWrapper(ex);
}
HbXmlLoaderBaseActions::ObjectMapItem HbXmlLoaderBaseActions::lookUp(const QString& type, const QString &name, const QString &plugin)
{   
    const bool nameNotEmpty = name.size() != 0;
    bool doLookUp = true;
    ObjectMapItem current;
    current.mObject = 0;
    current.mType = HbXml::OBJECT;
    
    if (nameNotEmpty) {
        ObjectMap::const_iterator it = mObjectMap.find(name);
        if (it != mObjectMap.end()) {
            current = it.value();
            
            if (!current.mObject) {
                mObjectMap.remove(name);
            }
            // CHECK DISABLED FOR NOW.
            /*
            if (current.mObject && !type.isEmpty()) {
                const QByteArray array = type.toUtf8();
                
                if (!current.mObject->inherits(array.data())) {                    
                    HB_DOCUMENTLOADER_PRINT( QString( "Existing object requested with invalid type" ) );
                    // We have object already in mObjectMap, but it does not fulfill
                    // all needs. So object look up has failed.
                    doLookUp = false;
                    current.mObject = 0;
                }
            }
            */
        }
    }
    
    if (doLookUp && !current.mObject) {
        QObject *obj = createObject(type, name, plugin);        
        if (obj) {
            current.mObject = obj;
            current.mType = qobject_cast<QGraphicsWidget*>(obj) ? HbXml::WIDGET : HbXml::OBJECT;
        }
        if (nameNotEmpty) {
            mObjectMap.insert(name, current);
        }
    }

    return current;
}
ObjectNodeInstance::Pointer ObjectNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped)
{
    QObject *object = 0;
    if (objectToBeWrapped)
        object = objectToBeWrapped;
    else
        object = createObject(nodeMetaInfo, context);

    Pointer instance(new ObjectNodeInstance(object));

    if (objectToBeWrapped)
        instance->setDeleteHeldInstance(false); // the object isn't owned

    instance->populateResetValueHash();

    return instance;
}
Ejemplo n.º 16
0
	cocos2d::Node* SceneReader::createNodeWithSceneFile(const char* pszFileName, ISceneReaderListener* listener )
    {
        unsigned long size = 0;
        const char* pData = 0;
		cocos2d::Node *pNode = NULL;
        do {
			  CC_BREAK_IF(pszFileName == NULL);
              pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pszFileName, "r", &size));
              CC_BREAK_IF(pData == NULL || strcmp(pData, "") == 0);
              cs::JsonDictionary *jsonDict = new cs::JsonDictionary();
              jsonDict->initWithDescription(pData);
			  pNode = createObject(jsonDict, NULL, listener);
              CC_SAFE_DELETE(jsonDict);
        } while (0);
        
        return pNode;
	}
static jobject android_net_wifi_getLinkLayerStats (JNIEnv *env, jclass cls, jint iface)  {

    wifi_stats_result_handler handler;
    memset(&handler, 0, sizeof(handler));
    handler.on_link_stats_results = &onLinkStatsResults;
    wifi_interface_handle handle = getIfaceHandle(env, cls, iface);
    int result = wifi_get_link_stats(0, handle, handler);
    if (result < 0) {
        ALOGE("android_net_wifi_getLinkLayerStats: failed to get link statistics\n");
        return NULL;
    }

    jobject wifiLinkLayerStats = createObject(env, "android/net/wifi/WifiLinkLayerStats");
    if (wifiLinkLayerStats == NULL) {
       ALOGE("Error in allocating wifiLinkLayerStats");
       return NULL;
    }

    setIntField(env, wifiLinkLayerStats, "beacon_rx", link_stat.beacon_rx);
    setIntField(env, wifiLinkLayerStats, "rssi_mgmt", link_stat.rssi_mgmt);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_be", link_stat.ac[WIFI_AC_BE].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_bk", link_stat.ac[WIFI_AC_BK].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_vi", link_stat.ac[WIFI_AC_VI].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_vo", link_stat.ac[WIFI_AC_VO].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_be", link_stat.ac[WIFI_AC_BE].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_bk", link_stat.ac[WIFI_AC_BK].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_vi", link_stat.ac[WIFI_AC_VI].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_vo", link_stat.ac[WIFI_AC_VO].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_be", link_stat.ac[WIFI_AC_BE].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_bk", link_stat.ac[WIFI_AC_BK].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_vi",  link_stat.ac[WIFI_AC_VI].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_vo", link_stat.ac[WIFI_AC_VO].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "retries_be", link_stat.ac[WIFI_AC_BE].retries);
    setLongField(env, wifiLinkLayerStats, "retries_bk", link_stat.ac[WIFI_AC_BK].retries);
    setLongField(env, wifiLinkLayerStats, "retries_vi", link_stat.ac[WIFI_AC_VI].retries);
    setLongField(env, wifiLinkLayerStats, "retries_vo", link_stat.ac[WIFI_AC_VO].retries);


    setIntField(env, wifiLinkLayerStats, "on_time", radio_stat.on_time);
    setIntField(env, wifiLinkLayerStats, "tx_time", radio_stat.tx_time);
    setIntField(env, wifiLinkLayerStats, "rx_time", radio_stat.rx_time);
    setIntField(env, wifiLinkLayerStats, "on_time_scan", radio_stat.on_time_scan);

    return wifiLinkLayerStats;
}
Ejemplo n.º 18
0
int main( int argc, char** argv )
{
  btDynamicsWorld* bw = initPhysics();
  osg::Group* root = new osg::Group;

  osg::ref_ptr< osgbInteraction::SaveRestoreHandler > srh = new osgbInteraction::SaveRestoreHandler;

  osg::Matrix m;

  m = osg::Matrix::rotate( .4, 0., 0., 1. ) * osg::Matrix::translate( 16., 0., 10. );
  btRigidBody *rb = createObject(root, m, srh.get());
  bw->addRigidBody(rb);
  
  m = osg::Matrix::rotate( osg::PI_2, 0, 1, 0 ) * osg::Matrix::translate( 0., 0., 10. );
  bw->addRigidBody(createWheel(root, m, srh.get()));

  m = osg::Matrix::rotate( 0, 0., 0., 1. ) * osg::Matrix::translate( -20., 0., 0. );
  bw->addRigidBody(createCow(root, m, srh.get()));

  root->addChild( osgbDynamics::generateGroundPlane( osg::Vec4( 0.f, 0.f, 1.f, 0.f ), bw ) );

  osgViewer::Viewer viewer;
  viewer.setUpViewInWindow( 30, 30, 768, 480, 1 );
  viewer.setSceneData( root );
  osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator;
  viewer.setCameraManipulator( tb );

  viewer.realize();
  srh->capture();

  viewer.addEventHandler(new myEventHandler(rb));
  viewer.addEventHandler( srh.get() );
  viewer.addEventHandler( new osgbInteraction::DragHandler(bw, viewer.getCamera() ) );

  double prevSimTime = 0.;
  while( !viewer.done() )
  {
    const double currSimTime = viewer.getFrameStamp()->getSimulationTime();
    bw->stepSimulation( currSimTime - prevSimTime );
    prevSimTime = currSimTime;
    viewer.frame();
  }

  return( 0 );
}
Ejemplo n.º 19
0
void PPPDlg::OnBnClickedOk()
{
    if( !UpdateData( TRUE ) ) return;

    if( m_objId.isNull() )
    {
        m_objId = createObject();
        if( m_objId.isNull() )
        {
            MessageBox( _T( "添加失败" ) );
            OnOK();
            return;
        }
    }

    writePropertyData();
    OnOK();
}
Ejemplo n.º 20
0
object *createObjects(int num)
{
	object *ptr = (object*) malloc(sizeof(object)*num);

	srand(time(NULL));
	int i =0 ; 
	while(i<num)
	{

		float p = (rand()%10)+1;
		float weight = (float)(rand()%7)+1 ;

		ptr[i]=createObject(p,weight,i);
		i++;

	}
return ptr;
}
Ejemplo n.º 21
0
void Editor::giveCursorPos(glm::vec2 pos)
{
	if (mode == 1 && clickTimer < FLT_EPSILON)
	{
		createObject(pos, currentColor);
		clickTimer = 0.3f;
	}
	if (mode == 2 && clickTimer < FLT_EPSILON)
	{
		createPlayer(pos);
		clickTimer = 0.3f;
	}
	if (mode == 3 && clickTimer < FLT_EPSILON)
	{
		createGoal(pos);
		clickTimer = 0.3f;
	}
}
    cocos2d::CCNode* CCJsonReader::createNodeWithJsonFile(const char* pszFileName)
    {
        unsigned long size = 0;
        const char* pData = 0;
		
        do {
              pData = (char*)(cocos2d::CCFileUtils::sharedFileUtils()->getFileData(pszFileName, "r", &size));
              CC_BREAK_IF(pData == NULL || strcmp(pData, "") == 0);
              cs::CSJsonDictionary *jsonDict = new cs::CSJsonDictionary();
              jsonDict->initWithDescription(pData);
              CCNode* gb = createObject(jsonDict,NULL);
              return gb;
              CC_SAFE_DELETE(jsonDict);
            
        } while (0);
        
        return NULL;
	}
Ejemplo n.º 23
0
/// Extern.
void
moviecliploader_class_init(as_object& where, const ObjectURI& uri)
{
	// This is going to be the where Number "class"/"function"
    Global_as& gl = getGlobal(where);

    as_object* proto = createObject(gl);;

    as_object* cl = gl.createClass(&moviecliploader_new, proto);
    attachMovieClipLoaderInterface(*proto);
  
	AsBroadcaster::initialize(*proto);

    as_object* null = 0;
    callMethod(&gl, NSV::PROP_AS_SET_PROP_FLAGS, proto, null, 1027);

	where.init_member(uri, cl, as_object::DefaultFlags); 
}
Ejemplo n.º 24
0
int createStorageObject(CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, struct p11Object_t *pObject)
{
	int index;
	unsigned int i, rc;

	rc = createObject(pTemplate, ulCount, pObject);

	if (rc) {
		return rc;
	}

	for (i = 0; attributesStorageObject[i].attribute.type; i++) {
		index = findAttributeInTemplate(attributesStorageObject[i].attribute.type, pTemplate, ulCount);

		if (index == -1) { /* The attribute is not present - is it optional? */
			if (attributesStorageObject[i].condition == AC_DEFAULT) {
				addAttribute(pObject, &attributesStorageObject[i].attribute);
			} else if (attributesStorageObject[i].condition != AC_OPTIONAL) { /* the attribute is not optional */
#ifdef DEBUG
				debug("[createStorageObject] Error creating storage object - the following attribute is not present!");
				dumpAttribute(&(attributesStorageObject[i].attribute));
#endif
				removeAllAttributes(pObject);
				return CKR_TEMPLATE_INCOMPLETE;
			}
		} else {
			addAttribute(pObject, &pTemplate[index]);

			/* The object is public */
			if ((pTemplate[index].type == CKA_PRIVATE ) &&
					(*(CK_BBOOL *)pTemplate[index].pValue == CK_FALSE)) {
				pObject->publicObj = TRUE;
			}

			/* The object is a token object */
			if ((pTemplate[index].type == CKA_TOKEN ) &&
					(*(CK_BBOOL *)pTemplate[index].pValue == CK_TRUE)) {
				pObject->tokenObj = TRUE;
			}
		}
	}

	return 0;
}
Ejemplo n.º 25
0
ossimObject* ossimImageHandlerFactory::createObject(const ossimKeywordlist& kwl,
                                                    const char* prefix)const
{
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimImageHandlerFactory::createObject(kwl, prefix) DEBUG:"
         << " entering ..." << std::endl;
   }
   ossimObject* result = (ossimObject*)0;
   const char* type = kwl.find(prefix, ossimKeywordNames::TYPE_KW);

   if(type)
   {
      if (ossimString(type).trim() == STATIC_TYPE_NAME(ossimImageHandler))
      {
         const char* lookup = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);

         if (lookup)
         {
            if(traceDebug())
            {
               ossimNotify(ossimNotifyLevel_DEBUG) << "BEBUG: filename " << lookup << std::endl;
            }
            // Call the open that takes a filename...
            result = this->open(kwl, prefix);//ossimFilename(lookup));
         }
      }
      else
      {
         result = createObject(ossimString(type));
         if(result)
         {
            result->loadState(kwl, prefix);
         }
      }
   }

   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG) << "ossimImageHandlerFactory::createObject(kwl, prefix) DEBUG: returning result ..." << std::endl;
   }
   return result;
}
Ejemplo n.º 26
0
TestCase * Grader07::testStringSearch(std::string cmds_filename, std::string input_filename)
{
  std::vector<StringSearchCmd> commands;

  Commands07 cmds07;
  cmds07.loadStringSearchCommmands(cmds_filename, commands);
  std::string to_search = cmds07.readStringFile(input_filename);

  if(commands.size() == 0){
    return failed("cannot read input file #1");
  }

  if(to_search == ""){
    return failed("cannot read input file #2");
  }

  Stopwatch watch;
  watch.start();

  IStringSearch * searcher = (IStringSearch *) createObject("IStringSearch");
  if(searcher == NULL){
    return nullObject("IStringSearch");
  }

  watch.pause();
  searcher->prepareText(to_search);
  watch.unpause();

  for(size_t i = 0; i < commands.size(); ++i){
    StringSearchCmd cmd = commands[i];
    std::vector<int> product_results = searcher->search(cmd.to_find);
    if(product_results.size() != cmd.positions.size()){
      return failed("incorrect return size");
    }
    std::sort(product_results.begin(), product_results.end());
    if(product_results != cmd.positions){
      return failed("at least one incorrect return index");
    }
  }

  watch.stop();
  return passed(watch.getTime());
}
Ejemplo n.º 27
0
AbstractObjectPtr
ObjectFactory::cloneObject(const AbstractObjectPtr anOriginalPtr)
{
    // *** use our factory to create a similar object
    AbstractObjectPtr myClonePtr = createObject(
                                       anOriginalPtr->getInternalName(),
                                       anOriginalPtr->theCenter,
                                       anOriginalPtr->theWidth,
                                       anOriginalPtr->theHeight);
    // *** copy all Properties that make sense
    myClonePtr->theProps = anOriginalPtr->theProps;

    // *** copy everything else
    myClonePtr->theToolTip = anOriginalPtr->theToolTip;
    myClonePtr->hasCustomToolTip = anOriginalPtr->hasCustomToolTip;

    // *** we're done
    return myClonePtr;
}
Ejemplo n.º 28
0
TestCase * Grader07::testSpellCheck(std::string filename)
{
  Commands07 cmds07;
  std::vector<std::string> words;
  std::vector<SpellCheckCmd> commands;

  cmds07.readReads("words", words);
  cmds07.loadSpellCheckCommands(filename, commands);

  if(words.size() == 0){
    return failed("cannot read input file #1");
  }

  if(commands.size() == 0){
    return failed("cannot read input file #2");
  }

  Stopwatch watch;
  watch.start();

  ISpellCheck * checker = (ISpellCheck *) createObject("ISpellCheck");
  if(checker == NULL){
    return nullObject("ISpellCheck");
  }

  watch.pause();
  checker->loadDictionary(words);
  watch.unpause();

  for(size_t i = 0; i < commands.size(); ++i){
    SpellCheckCmd cmd = commands[i];
    std::vector<std::string> product_corrections = checker->suggestCorrections(cmd.word);
    watch.pause();
    std::sort(product_corrections.begin(), product_corrections.end());
    if(product_corrections != cmd.corrections){
      return failed("corrections mismatch");
    }
    watch.unpause();
  }

  watch.stop();
  return passed(watch.getTime());
}
Ejemplo n.º 29
0
TestCase * Grader07::testCompress(std::string input_filename, std::string output_filename)
{
  Commands07 cmds07;
  std::string input = cmds07.readStringFile(input_filename);

  Stopwatch watch;
  watch.start();

  ICompress * compressor = (ICompress *) createObject("ICompress");
  if(compressor == NULL){
    return nullObject("ICompress");
  }

  std::string output = compressor->compress(input);
  watch.stop();

  cmds07.writeStringFile(output_filename, output);
  return passed(watch.getTime()+output.size());
}
Ejemplo n.º 30
0
sds catAppendOnlyExpireAtCommand(sds buf, robj *key, robj *seconds) {
    int argc = 3;
    long when;
    robj *argv[3];

    /* Make sure we can use strtol */
    seconds = getDecodedObject(seconds);
    when = time(NULL)+strtol(seconds->ptr,NULL,10);
    decrRefCount(seconds);

    argv[0] = createStringObject("EXPIREAT",8);
    argv[1] = key;
    argv[2] = createObject(REDIS_STRING,
        sdscatprintf(sdsempty(),"%ld",when));
    buf = catAppendOnlyGenericCommand(buf, argc, argv);
    decrRefCount(argv[0]);
    decrRefCount(argv[2]);
    return buf;
}