Esempio n. 1
0
/* HardwareConcurrency() - How much parallelism does the hardware have?
 *
 * Due to a very painful bug in Visual C++, we use a wrapper function for
 * what should be a simple library call.
 */
static unsigned int HardwareConcurrency(void)
    {
    static unsigned int ThreadCount;

    if(ThreadCount == 0)
        {
        try {
            // compiler thinks next line can't throw exception (true, except for bug)
            ThreadCount = std::thread::hardware_concurrency();
            // have to convince compiler an exception could be thrown...
            unique_ptr<char[]>    Dummy(new char[1]);
            }
        catch (...)
            {
            fprintf(stderr,
                "Can't happen: hardware_concurrency() threw an exception.\n"
                "Are you running under Windows/AppVerifier with HighVersionLie checked?\n"
                "If so, you may want to do something like:\n"
                "    appverif -disable HighVersionLie -for blacc.exe\n"
                );
            throw;
            }
        // note that 0 is essentially "don't know"
        if(ThreadCount == 0)
            ThreadCount = 1;
        }

    return ThreadCount;
    }
	ListNode *deleteDuplicates(ListNode *head) {
		ListNode Dummy(-1);Dummy.next=head;
		
		ListNode* p=head,*pre=&Dummy;
		//if(p==nullptr) return nullptr;
		bool hasduplicate=0;
		while(p)
		{
			if(p->next==nullptr)
			{
				if(hasduplicate)
					pre->next=p->next;
				break;
			}
			if(p->val==p->next->val)
			{
				hasduplicate=1;
				p=p->next;
			}
			else
			{
				if(!hasduplicate)
					pre=p,p=p->next;
				else
					hasduplicate=0,pre->next=p->next,p=p->next;
			}
		}
		
		return Dummy.next;
	}
TEST(MaybeTest, MoveAssign) {
    Maybe<Dummy> val;
    {
        Maybe<Dummy> val2 = Dummy();
        val = std::move(val2);
    }
}
 ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
     if (l1 == NULL) return l2;
     if (l2 == NULL) return l1;
     
     // Create a Dummy Node where is the beginning of the new list
     ListNode Dummy(0);
     ListNode* New_L = &Dummy;
     
     // Letting New List's next point to the one we want from L1 or L2
     // This will loop until either L1 or L2 reach NULL
     for (; l1 != NULL && l2 != NULL ; New_L = New_L->next) {
         if ( l1->val < l2->val ) {
             New_L -> next = l1; 
             l1 = l1->next;
         }
         
         else {
             New_L -> next = l2;
             l2 = l2->next;
         }
     }
     
     New_L -> next = (l1 == NULL) ? l2:l1;
     return Dummy.next;
     
 }   
Esempio n. 5
0
QVector <double> KoDummyColorProfile::getEstimatedTRC() const

{
    QVector<double> Dummy(3);
    Dummy.fill(2.2);
    return Dummy;
}
Esempio n. 6
0
/**
 * moved the fix for #917 here - check a house's ability to handle base plan before it actually tries to generate a base plan, not at game start
 * (we have no idea what houses at game start are supposed to be able to do base planning, so mission maps f**k up)
 */
bool HouseExt::ExtData::CheckBasePlanSanity() {
	auto House = this->AttachedToObject;
	// this shouldn't happen, but you never know
	if(House->ControlledByHuman() || House->IsNeutral()) {
		return true;
	}

	const char *errorMsg = "AI House of country [%s] cannot build any object in %s. The AI ain't smart enough for that.\n";
	bool AllIsWell(true);

	// if you don't have a base unit buildable, how did you get to base planning?
	// only through crates or map actions, so have to validate base unit in other situations
	auto pArray = &RulesClass::Instance->BaseUnit;
	bool canBuild = false;
	for(int i = 0; i < pArray->Count; ++i) {
		auto Item = pArray->GetItem(i);
		if(House->CanExpectToBuild(Item)) {
			canBuild = true;
			break;
		}
	}
	if(!canBuild) {
		AllIsWell = false;
		Debug::DevLog(Debug::Error, errorMsg, House->Type->ID, "BaseUnit");
	}

	auto CheckList = [House, errorMsg, &AllIsWell]
			(DynamicVectorClass<BuildingTypeClass *> *const List, char * const ListName) -> void {
		if(!House->FirstBuildableFromArray(List)) {
			AllIsWell = false;
			Debug::DevLog(Debug::Error, errorMsg, House->Type->ID, ListName);
		}
	};

	// commented out lists that do not cause a crash, according to testers
//	CheckList(&RulesClass::Instance->Shipyard, "Shipyard");
	CheckList(&RulesClass::Instance->BuildPower, "BuildPower");
	CheckList(&RulesClass::Instance->BuildRefinery, "BuildRefinery");
	CheckList(&RulesClass::Instance->BuildWeapons, "BuildWeapons");

//			CheckList(&RulesClass::Instance->BuildConst, "BuildConst");
//			CheckList(&RulesClass::Instance->BuildBarracks, "BuildBarracks");
//			CheckList(&RulesClass::Instance->BuildTech, "BuildTech");
//			CheckList(&RulesClass::Instance->BuildRadar, "BuildRadar");
//			CheckList(&RulesClass::Instance->ConcreteWalls, "ConcreteWalls");
//			CheckList(&RulesClass::Instance->BuildDummy, "BuildDummy");
//			CheckList(&RulesClass::Instance->BuildNavalYard, "BuildNavalYard");

	auto pCountryData = HouseTypeExt::ExtMap.Find(House->Type);
	auto Powerplants = pCountryData->GetPowerplants();
	DynamicVectorClass<BuildingTypeClass*> Dummy(Powerplants.size(), const_cast<BuildingTypeClass**>(Powerplants.begin()));
	CheckList(&Dummy, "Powerplants");

//			auto pSide = SideClass::Array->GetItem(curHouse->Type->SideIndex);
//			auto pSideData = SideExt::ExtMap.Find(pSide);
//			CheckList(&pSideData->BaseDefenses, "Base Defenses");

	return AllIsWell;
}
Esempio n. 7
0
bool cBlockArea::SaveToSchematicFile(const AString & a_FileName)
{
	cFastNBTWriter Writer("Schematic");
	Writer.AddShort("Width", m_SizeX);
	Writer.AddShort("Height", m_SizeY);
	Writer.AddShort("Length", m_SizeZ);
	Writer.AddString("Materials", "Alpha");
	if (HasBlockTypes())
	{
		Writer.AddByteArray("Blocks", (const char *)m_BlockTypes, GetBlockCount());
	}
	else
	{
		AString Dummy(GetBlockCount(), 0);
		Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size());
	}
	if (HasBlockMetas())
	{
		Writer.AddByteArray("Data", (const char *)m_BlockMetas, GetBlockCount());
	}
	else
	{
		AString Dummy(GetBlockCount(), 0);
		Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
	}
	// TODO: Save entities and block entities
	Writer.BeginList("Entities", TAG_Compound);
	Writer.EndList();
	Writer.BeginList("TileEntities", TAG_Compound);
	Writer.EndList();
	Writer.Finish();
	
	// Save to file
	cGZipFile File;
	if (!File.Open(a_FileName, cGZipFile::fmWrite))
	{
		LOG("Cannot open file \"%s\" for writing.", a_FileName.c_str());
		return false;
	}
	if (!File.Write(Writer.GetResult()))
	{
		LOG("Cannot write data to file \"%s\".", a_FileName.c_str());
		return false;
	}
	return true;
}
Esempio n. 8
0
void Dynamixel::uDelay(uint32 uTime) {
    uint32 cnt, max;
    static uint32 tmp = 0;

    for( max=0; max < uTime; max++)
    {
        for( cnt=0; cnt < 10 ; cnt++ )
        {
            tmp +=Dummy(cnt);
        }
    }
    //tmpdly = tmp;
}
void uDelay(u32 uTime) {
	u32 cnt, max;
	static u32 tmp = 0;

	for( max=0; max < uTime; max++)
	{
		for( cnt=0; cnt < 10 ; cnt++ )
		{
			tmp +=Dummy(cnt);
		}
	}
	tmpdly = tmp;
}
Esempio n. 10
0
AString cSchematicFileSerializer::SaveToSchematicNBT(const cBlockArea & a_BlockArea)
{
	cFastNBTWriter Writer("Schematic");
	Writer.AddShort("Width",  static_cast<Int16>(a_BlockArea.m_Size.x));
	Writer.AddShort("Height", static_cast<Int16>(a_BlockArea.m_Size.y));
	Writer.AddShort("Length", static_cast<Int16>(a_BlockArea.m_Size.z));
	Writer.AddString("Materials", "Alpha");
	if (a_BlockArea.HasBlockTypes())
	{
		Writer.AddByteArray("Blocks", reinterpret_cast<const char *>(a_BlockArea.GetBlockTypes()), a_BlockArea.GetBlockCount());
	}
	else
	{
		AString Dummy(a_BlockArea.GetBlockCount(), 0);
		Writer.AddByteArray("Blocks", Dummy.data(), Dummy.size());
	}
	if (a_BlockArea.HasBlockMetas())
	{
		Writer.AddByteArray("Data", reinterpret_cast<const char *>(a_BlockArea.GetBlockMetas()), a_BlockArea.GetBlockCount());
	}
	else
	{
		AString Dummy(a_BlockArea.GetBlockCount(), 0);
		Writer.AddByteArray("Data", Dummy.data(), Dummy.size());
	}

	Writer.AddInt("WEOffsetX", a_BlockArea.m_WEOffset.x);
	Writer.AddInt("WEOffsetY", a_BlockArea.m_WEOffset.y);
	Writer.AddInt("WEOffsetZ", a_BlockArea.m_WEOffset.z);

	// TODO: Save entities and block entities
	Writer.BeginList("Entities", TAG_Compound);
	Writer.EndList();
	Writer.BeginList("TileEntities", TAG_Compound);
	Writer.EndList();
	Writer.Finish();

	return Writer.GetResult();
}
Esempio n. 11
0
void Dynamixel::nDelay(uint32 nTime) {
    uint32 cnt, max;
    cnt=0;
    static uint32 tmp = 0;

    for( max=0; max < nTime; max++)
    {
        //for( cnt=0; cnt < 10 ; cnt++ )
        //{
        tmp +=Dummy(cnt);
        //}
    }
    //tmpdly = tmp;
}
    ListNode* reverseBetween(ListNode* head, int m, int n) {
      if (m == n) return head;
      n -= m;
      ListNode Dummy(0);
      Dummy.next = head;
      ListNode* ptr = &Dummy;
      while (--m) ptr = ptr->next;

      ListNode* reversePtr = ptr->next;
      while (n--) {
        ListNode * tmp = reversePtr->next;
        reversePtr->next = tmp->next;
        tmp->next = ptr->next;
        ptr->next = tmp;
      }

      return Dummy.next;
    }
Esempio n. 13
0
//***********************************************************************
int CParser::GetNextToken()		// return next token in the script
//***********************************************************************
{
	if (!m_lpScript) return I_EOF;

	int i;
	int wWordLen, wLen;
	pCParseToken pToken;

	LPSTR pWord;

	if (wWordLen = GetNextWord())
	{
		pWord = m_lpScript;			// the word it just located
		m_lpScript += wWordLen;		// just after this word

		for (i=0; (pToken = &TokenList[i]) && pToken->GetID(); i++)
		{
			LPSTR lpToken = pToken->GetToken();
			wLen = pToken->GetTokenLen();
			if ((wWordLen == wLen) &&
				(_fstrnicmp(lpToken, pWord, wLen) == 0))
			{
				BOOL bResult = TRUE;
				for (int q=0; bResult && q<pToken->GetParams(); q++)
					bResult = GetNextNum(&m_Params[q]);
				if (!bResult)
					RecordError(pToken, ERR_INSUF);
				return bResult ? pToken->GetID() : NULL;	// found one.
			}
		}
		// cannot find that command
		char command[100];
		command[0] = 0;
		lstrcpyn(command, pWord, wWordLen+1);
		CParseToken Dummy((LPSTR)command, 0, 0);
		RecordError(&Dummy, ERR_UNKNOWN);
		return NULL;
	}
	// no more words in the script
	return I_EOF;
}
Esempio n. 14
0
namespace PrototypeIDVariant {

enum Warrior_ID {Infantryman_ID, Archer_ID, Horseman_ID };

class Warrior; // forward declaration
typedef std::map< Warrior_ID, Warrior* > Registry;

Registry& getRegistry() {
  static Registry instance;
  return instance;
}


class Dummy{};

class Warrior {
public:
  virtual Warrior* clone() = 0;
  virtual string info() = 0;
  virtual ~Warrior() {}
  static Warrior* createWarrior( Warrior_ID id ) {
    Registry& r = getRegistry();
    if( r.find(id) != r.end() )
      return r[id]->clone();
    return 0;
  }
protected:
  static void addProtopype( Warrior_ID id, Warrior* prototype) {
    Registry& r = getRegistry();
    r[id] = prototype;
  }
  static void removePrototype( Warrior_ID id ) {
    Registry& r = getRegistry();
    r.erase( r.find( id ) );
  }
};


class Infantryman : public Warrior {
public:
  Warrior* clone() {
    return new Infantryman( * this );
  }
  string info() {
    return "Infantryman";
  }
private:
  Infantryman( Dummy ) {
    Warrior::addProtopype( Infantryman_ID, this );
  }
  Infantryman() {}
  static Infantryman prototype;
};


class Archer : public Warrior {
public:
  Warrior* clone() {
    return new Archer( * this );
  }
  string info() {
    return "Archer";
  }
private:
  Archer( Dummy ) {
    Warrior::addProtopype( Archer_ID, this );
  }
  Archer() {}
  static Archer prototype;
};


class Horseman : public Warrior {
public:
  Warrior* clone() {
    return new Horseman( * this );
  }
  string info() {
    return "Horseman";
  }
private:
  Horseman( Dummy ) {
    Warrior::addProtopype( Horseman_ID, this );
  }
  Horseman() {}
  static Horseman prototype;
};

Infantryman Infantryman::prototype = Infantryman( Dummy() );
Archer Archer::prototype = Archer( Dummy() );
Horseman Horseman::prototype = Horseman( Dummy() );



void aPrototype() {
  std::vector< Warrior* > v;
  v.push_back( Warrior::createWarrior( Infantryman_ID ) );
  v.push_back( Warrior::createWarrior( Archer_ID ) );
  v.push_back( Warrior::createWarrior( Horseman_ID ) );
  for( size_t i = 0; i < v.size(); ++i )
    cout << v[i]->info() << endl;
}

}
Esempio n. 15
0
void init(){
  bool cOut = pa("-c"), dOut = pa("-d");
  
  if(cOut){
    colorOut.init(pa("-c"));
  }
  if(dOut){
    depthOut.init(pa("-d"));
  }
  
  if(cOut || dOut){
    prevGUI << (cOut ? Image().handle("color") : Dummy())
            << (dOut ? Image().handle("depth") : Dummy())
            << Create();
  }

  gui << Draw3D().handle("draw")
      << ( VBox().minSize(10,2)
           << FSlider(-10,10,0).out("x").label("translate x")
           << FSlider(-10,10,0).out("y").label("translate y")
           << FSlider(1.5,10,0).out("z").label("translate z")
           
           << FSlider(-4,4,0).out("rx").label("rotate x")
           << FSlider(-4,4,0).out("ry").label("rotate y")
           << FSlider(-4,4,0).out("rz").label("rotate z")

           << ((cOut||dOut) ? (const GUIComponent&)Button("show","hide").label("preview").handle("preview") 
               : (const GUIComponent&)Dummy() )
           << Button("reset view").handle("resetView")
         )
      << Show();

  
  if(cOut || dOut){
    gui["preview"].registerCallback(utils::function(&prevGUI,&GUI::switchVisibility));
    if(dOut){
      ImageHandle d = prevGUI["depth"];
      d->setRangeMode(ICLWidget::rmAuto);
    }
  }
  
  Camera defaultCam(Vec(4.73553,-3.74203,8.06666,1),
                    Vec(-0.498035,0.458701,-0.735904,1),
                    Vec(0.787984,-0.116955,-0.604486,1));
  scene.addCamera( !pa("-cam").as<bool>() ? defaultCam : Camera(*pa("-cam")));
  initDepthCam = scene.getCamera(0);
  
  if(pa("-ccam")){
    scene.addCamera(*pa("-ccam"));
    Mat D=scene.getCamera(0).getCSTransformationMatrix();
    Mat C=scene.getCamera(1).getCSTransformationMatrix();
    
    relTM = new Mat( C * D.inv() );
  }

  SceneObject* ground = SceneObject::cuboid(0,0,0,200,200,3);
  ground->setColor(Primitive::quad,GeomColor(100,100,100,255));
  
  scene.addObject(ground);
  if(pa("-object")){
    scene.addObject( (obj = new SceneObject(*pa("-object"))) );
  }else{
    scene.addObject( (obj = SceneObject::cube(0,0,3, 3) ) );
  }
  obj->setColor(Primitive::quad, GeomColor(0,100,255,255));
  obj->setColor(Primitive::triangle, GeomColor(0,100,255,255));
  obj->setColor(Primitive::polygon, GeomColor(0,100,255,255));
  obj->setVisible(Primitive::line | Primitive::vertex, false);
  
  gui["draw"].link(scene.getGLCallback(0));
  gui["draw"].install(scene.getMouseHandler(0));

  scene.setDrawCamerasEnabled(false);

  scene.addCamera(scene.getCamera(0));

}
int main()	{

	EifList<int> TestList (True), TestList2 (True);
	EifIterator TestIt, *TestItptr;

	int d[] = {1, 2, 3, 1, 4, 5, 6, 7, 8, 8, 9, 10, -1}, i;

	for (i = 0; d [i] != -1; i++)	{
		cout << "\n" << d[i];
		TestList.Add (d[i]);
	}

	cout << "\n\nList Test\n";

	cout << "Should be 10\t" << TestList.Count() << "\n";

	TestList.Remove (11);

	cout << "Should be 10\t" << TestList.Count() << "\n";


	TestList.Remove (9);

	cout << "Should be 9\t" << TestList.Count() << "\n";

	TestList.Search (9);

	cout <<"Should be 0\t" << TestList.Found() << "\n";

	TestList.Search (6);

	cout <<"Should be 1:\t" << TestList.Found() << "\n";

	cout << "Should be 6:\t" << TestList.FoundItem() << "\n";

	IC (0, TestList);

	TestItptr = new EifIterator (TestList);

	IC (1, TestList);


	EifIterator TestIt2 = *TestItptr;

	IC (2, TestList);

	TestIt2 = TestIt;

	IC (1, TestList);

	DummyIt (1, *TestItptr, TestList);

	delete TestItptr;
	TestItptr = NULL;

	IC (0, TestList);

	Dummy (TestList);

	IC (0, TestList);

	TestIt = TestList.Iterator();

	IC (1, TestList);

	while (!TestIt.Finished())	{
		cout <<'\n' << TestList.Item (TestIt);
		TestIt.Forth();
	}

	IC (0, TestList);

	TestIt = TestList2.Iterator();

	IC (0, TestList2);

	TestList2.Add (1);

	TestIt.First();

	IC (1, TestList2);

	TestIt.Forth();

	IC (0, TestList2);

	return 0;
}
void bimanual_ds::Update()
{
	if (Command==Com_Stop){
		dt_=0;
	} else if (Command==Com_Break)
	{
		dt_=Break_*dt_;
	}
	Frame_transform_U_T_C();

	U_l_=K_l_*(S_VO_C_L_-S_R_L_);
	U_r_=K_r_*(S_VO_C_R_-S_R_R_);

	if (P_O_.Norm2()!=0)
	{
		DGamma_=0.1*(1-Gamma_)/P_O_.Norm2();
	}

	Vector Dummy(6);Dummy.Zero();
	Dummy(3)=S_O_(3);Dummy(4)=S_O_(4);Dummy(5)=S_O_(5);

    // Eq. 9a
	DS_VO_=(A_1_*(S_VO_-S_O_*Gamma_)+DS_O_*Gamma_+S_O_*DGamma_+U_l_+U_r_)/3;

//	DS_VO_=(A_1_*(S_VO_-S_O_*Gamma_)+DS_O_*Gamma_+S_O_*DGamma_+Dummy*DGamma_);

//	cout<<DS_VO_(0)<<" "<<DS_VO_(1)<<" "<<DS_VO_(2)<<" "<<DS_VO_(3)<<" "<<DS_VO_(4)<<" "<<DS_VO_(5)<<endl;



	if (Command==Com_Safe)
	{
		O_U_VO_=O_U_O_*Gamma_O_+O_U_VO_*(1-Gamma_O_);
	}

    S_VO_ = S_VO_ + DS_VO_*dt_;

/*	Pos_Debug.position.x=U_l_(0);
	Pos_Debug.position.y=U_l_(1);
	Pos_Debug.position.z=U_l_(2);
	Pos_Debug.orientation.x=U_l_(3);
	Pos_Debug.orientation.y=U_l_(4);
	Pos_Debug.orientation.z=U_l_(5);
	pub_Debug.publish(Pos_Debug);*/
	//	O_U_VO_=O_U_VO_+DO_VO_*dt_;
	/*	DO_VO_.Print("DO_VO_");*/

	U_O_VO_Matrix_=ConvertQuatsToMats(O_U_VO_);

	C_O_U_Matrix_=U_O_C_Matrix_.Inverse();
	C_O_VO_Matrix_=U_O_VO_Matrix_*C_O_U_Matrix_;


	DS_R_L_=DS_VO_+K_l_*(S_R_L_-S_VO_C_L_);
	S_R_L_=S_R_L_+DS_R_L_*dt_;


	DS_R_R_=DS_VO_+K_r_*(S_R_R_-S_VO_C_R_);
	S_R_R_=S_R_R_+DS_R_R_*dt_;




	Gamma_=Gamma_+DGamma_*dt_*0.2;
	if (Gamma_>0.99) Gamma_=1;




//	if ((P_R_U_L_(2)<0.1)||(P_R_U_R_(2)<0.2))
//	{
//		if (Command!=Com_Stop)
//		{
//			FLag_of_command=0;
//		}
//		Command=Com_Stop;
//		if (FLag_of_command==0)
//		{
//			cout<<"The robot is immediately stopped"<<endl;
//			FLag_of_command=1;
//		}
//	}
	Frame_transform_C_T_U();
	//	cout<<"Norm2() "<<(P_O_-P_VO_).Norm2()+(P_R_L_-P_O_C_L_).Norm2()+(P_R_R_-P_O_C_R_).Norm2()<<endl;
//	if ((((P_O_-P_VO_).Norm2()+(P_R_L_-P_O_C_L_).Norm2()+(P_R_R_-P_O_C_R_).Norm2()<0.01))||P_VO_(0)>0.3)
//	if ((((P_O_-P_VO_).Norm2()+(P_R_L_-P_O_C_L_).Norm2()+(P_R_R_-P_O_C_R_).Norm2()<0.001)))
//	{
	/*	if (Command!=Com_Break)
		{
			FLag_of_command=0;
		}
		Command=Com_Break;
		if (FLag_of_command==0)
		{
			cout<<"The robot's speed is reduced"<<endl;
			FLag_of_command=1;
		}*/
//	}
	//	Gamma_O_=1.0;

    if  (P_U_O_(0)>-0.5)
	{
		Gamma_O_=1.0;
		State_Orie=Per_Follow;
	}

	//Print_states();
}
TEST(MaybeTest, Lifecycle) {
    Maybe<Dummy> val = make_nothing<Dummy>();

    Maybe<Dummy> val2 = make_value(Dummy());
}