示例#1
0
/*
	一开始,我让 读队列线程 忙等写队列线程 完成写入标记。
	我原本觉得写队列线程递增队列尾指针和写入完成标记间只有一两条机器指令,所以忙等是完全没有问题的。
	但是我错了,再极端情况下(队列中数据很少,并发线程非常多),也会造成问题。
	后来的解决方法是,修改了出队列 api 的语义。
	原来的语义是:
		当队列为空的时候,返回一个 NULL ,否则就一定从队列头部取出一个数据来。
	修改后的语义是:
		返回 NULL 表示取队列失败,这个失败可能是因为队列空,也可能是遇到了竞争。

	我们这个队列仅在一处使用,在使用环境上看,修改这个 api 语义是完全成立的,
	修改后完全解决了我前面的问题,并极大的简化了并发队列处理的代码。
*/
struct message_queue * 
skynet_globalmq_pop() {
	struct global_queue *q = Q;
	uint32_t head =  q->head;
	uint32_t head_ptr = GP(head);

	// 队列为空
	if (head_ptr == GP(q->tail)) {
		return NULL;
	}

	// head所在位置没有mq
	if(!q->flag[head_ptr]) {
		return NULL;
	}

	__sync_synchronize();	// 同步指令 保证前面的指令执行完毕,才会执行后面的指令

	struct message_queue * mq = q->queue[head_ptr];

	// CAS原子性操作 如果q->head == head,则q->head=head+1; 移动头部
	if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) {
		return NULL;
	}

	q->flag[head_ptr] = false; // 消息已经被取走

	return mq;
}
示例#2
0
struct message_queue * 
skynet_globalmq_pop() {
	struct global_queue *q = Q;
	uint32_t head =  q->head;
	uint32_t head_ptr = GP(head);
	if (head_ptr == GP(q->tail)) {
		return NULL;
	}

	if(!q->flag[head_ptr]) {
		return NULL;
	}

	//__sync_synchronize();
	::MemoryBarrier();

	struct message_queue * mq = q->queue[head_ptr];

	/*
	if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) {
		return NULL;
	}
		*/

	// todo ¸Ð¾õ²»Ì«¶Ô
	uint32_t ret = InterlockedCompareExchange(&q->head, head+1, head);
	//if (ret != head+1)
	//	return NULL;

	q->flag[head_ptr] = false;

	return mq;
}
示例#3
0
eFlag Tree::insertRule(Sit S, XSLElement *tmpl)
{
  double prio;
  Attribute *a = tmpl -> atts.find(XSLA_PRIORITY);
  if (!a)
    prio = defaultPriority(tmpl);
  else
    {
      if (a -> cont.toDouble(prio))
	Err(S, ET_BAD_NUMBER);
    };
  QName q; 
  GP( QName ) mode = NULL;
  
  if (!!(a = tmpl -> atts.find(XSLA_NAME)))
    E( tmpl -> setLogical(S, q, a -> cont, FALSE) );
  
  if (q.getLocal() != UNDEF_PHRASE && 
      subtrees.getCurrent() -> getStructure() -> 
      rules().findByName(*this, q))
    {
      Str fullName;
      expandQStr(q, fullName);
      
      Err1(S, ET_DUPLICATE_RULE_NAME, fullName);
    };
  
  if (!!(a = tmpl -> atts.find(XSLA_MODE)))
    E( tmpl -> setLogical(S, *(mode = new QName), 
			  a -> cont, FALSE) );
  
  subtrees.getCurrent() -> getStructure() -> 
    rules().insert(new RuleItem(tmpl,prio,q,mode.keep()));
  return OK;
}
示例#4
0
eFlag Tree::extractUsedSets(Sit S, Element *e) 
{
    Attribute *a = e -> atts.find(XSLA_USE_ATTR_SETS); 
    if (a) 
    {
	QNameList *names = e -> attSetNames(TRUE);
	names -> freeall(FALSE);
	char *p, *q;

	q = (char*) (a -> cont);
	skipWhite(q);
	p = q;
	int i = strcspn(q, theWhitespace);
	while (*q && i) {
	    q += i;
	    char save = *q;
	    *q = 0;

	    Str token = p;
	    GP( QName ) name = new QName;
	    E( e -> setLogical(S, *name, token, FALSE) );

	    names -> append( name.keep() );
	    *q = save;
	    skipWhite(q);
	    p = q;
	    i = strcspn(q, theWhitespace);
	}

    }
    return OK;
}
示例#5
0
eFlag Tree::getSpaceNames(Sit S, Element &e, Str &str, SpaceNameList &where)
{
  char *p, *q;
  q = (char*)str;
  skipWhite(q);
  p = q;
  int i = strcspn(q, theWhitespace);
  while (*q && i) 
    {
      q += i;
      char save = *q;
      *q = 0;
      
      Str token = p;
      QName name;
      E( e.setLogical(S, name, token, FALSE) );
      GP(EQName) ename = new EQName;
      expandQ(name, *ename);
      where.append(ename.keep());

      *q = save;
      skipWhite(q);
      p = q;
      i = strcspn(q, theWhitespace);
    }

  return OK;
}
示例#6
0
bool CGameString::LoadConfig()
{
  char* fileName = "GameString.txt";
  if (!IsFileExist(fileName, TXT_PATH))
    copyFile(fileName, TXT_PATH);
  string fullFilePath = getFilePath(fileName, TXT_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  char buffer[256];  
  ifstream in(fullFilePath);  
  if (! in.is_open())  
  { 
    cout << "Error opening file ItemProperty"; 
    return false; 
  }
  int Line = 0;
  while (EOF != in.peek() )  
  { 
    in.getline (buffer,256);
    GParse GP(buffer);
    GP.getInt();
    string Descibe = GP.getString();
    GameStrings.push_back(/*FontToUTF8*/(Descibe.c_str()));
  }  
  return true;
}
示例#7
0
bool CPropertySet::LoadConfig()
{
#ifdef _FILESYSTEM
  char* fileName = "PropertySet.txt";
  if (!IsFileExist(fileName, TXT_PATH))
    copyFile(fileName, TXT_PATH);
  string fullFilePath = getFilePath(fileName, TXT_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  char buffer[256];  
  ifstream in(fullFilePath);  
  if (! in.is_open())  
  { 
    cout << "Error opening file PropertySet"; 
    return false; 
  }
  int Line = 0;
  while (EOF != in.peek() )  
  { 
    in.getline (buffer,256);
    GParse GP(buffer);
    PropertySet Item;
    Item.Idx = GP.getInt();
    Item.Id = GP.getInt();
    PropertySets.push_back(Item);
  }
  return true;
#endif // _FILESYSTEM

  return true;
}
示例#8
0
uintptr_t _SE0(uintptr_t xax, uintptr_t xbx,
               uintptr_t xcx, uintptr_t xdx,
               uintptr_t xsi, uintptr_t xdi)
{
    UNUSED(xsi), UNUSED(xdi);

    switch (xax)
    {
    case SE_ECREATE:
        return _ECREATE(reinterpret_cast<page_info_t*>(xbx));

    case SE_EADD:
        return _EADD(reinterpret_cast<page_info_t*>(xbx),
                     reinterpret_cast<void*>(xcx));

    case SE_EINIT:
        return _EINIT(reinterpret_cast<secs_t*>(xbx),
                      reinterpret_cast<enclave_css_t *>(xcx),
                      reinterpret_cast<token_t *>(xdx));

    case SE_EREMOVE:
        return _EREMOVE(reinterpret_cast<void*>(xcx));

    default:
        GP();
    }

    return 0;
}
示例#9
0
文件: wgtnet.cpp 项目: Aleyasen/Alaki
void TTop2FriendNet::PlotPick2VsProb2nd(const PWgtNet& Net, const int& NRuns, const double& StepP, const TStr& OutFNm, 
                                        TStr Desc, bool PlotTop2, bool PlotBtm2, bool PlotRnd2) {
  TTop2FriendNet Top2(Net);  Net->MulEdgeWgt(-1.0); 
  TTop2FriendNet Btm2(Net);  Net->MulEdgeWgt(-1.0); // change back
  THash<TFlt, TMom> Top2H, Btm2H, Rnd2H;
  for (int run = 0; run < NRuns; run++) {
    TExeTm ExeTm;
    printf("run %d\n", run);
    for (double p = 0; p <= 1; p += StepP) {
      if (PlotTop2) { Top2H.AddDat(p).Add(Top2.GetTop2WccSz(p)); }
      if (PlotBtm2) { Btm2H.AddDat(p).Add(Btm2.GetTop2WccSz(p)); }
      if (PlotRnd2) { Rnd2H.AddDat(p).Add(Top2.GetRnd2WccSz(p)); }
      printf(".");
    }
    printf("[%s]\n", ExeTm.GetStr());
    TFltTrV Top2V, Btm2V, Rnd2V;
    GetAvgSDevV(Top2H, Top2V);
    GetAvgSDevV(Btm2H, Btm2V);
    GetAvgSDevV(Rnd2H, Rnd2V);
    TGnuPlot GP("ccVsP-"+OutFNm, TStr::Fmt("%s (%d, %d, %f)", Desc.CStr(), Net->GetNodes(), 
      Net->GetEdges(), Net->GetEdgeWgt()));
    GP.SetXYLabel("Prob of taking 2nd edge", "Size of largest connected component");
    if (! Top2V.Empty()) { GP.AddErrBar(Top2V, "TOP", ""); }
    if (! Rnd2V.Empty()) { GP.AddErrBar(Rnd2V, "RND", ""); }
    if (! Btm2V.Empty()) { GP.AddErrBar(Btm2V, "BTM", ""); }
    GP.SavePng();
  }
}
示例#10
0
bool CShop::LoadConfig()
{

  char* fileName = "ShopItem.txt";
  if (!IsFileExist(fileName, TXT_PATH))
    copyFile(fileName, TXT_PATH);
  string fullFilePath = getFilePath(fileName, TXT_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  char buffer[256];  
  ifstream in(fullFilePath);  
  if (! in.is_open())  
  { 
    cout << "Error opening file ShopItem"; 
    return false; 
  }
  int Line = 0;
  while (EOF != in.peek() )  
  { 
    in.getline (buffer,256);
    GParse GP(buffer);
    ShopData Item;
    Item.Id = GP.getInt();
    Item.money = GP.getInt();
    _ShopDatas.push_back(Item);
  }
  return true;
}
示例#11
0
文件: b_0_48.cpp 项目: jakexie/micmac
void BenchGaussjPrec(INT N,INT M)
{
    GaussjPrec  GP(N,M);

    for (INT y=0; y<N ; y++)
    {
        for (INT x=0; x<N ; x++)
            GP.M()(x,y) = NRrandom3()-0.5 + 2 * N * (x==y);
		{
        for (INT x=0; x<M ; x++)
            GP.b()(x,y) = NRrandom3();
		}
    }

    bool OK = GP.init_rec();
    BENCH_ASSERT(OK);
	{
    for (INT y=0; y<N ; y++)
        for (INT x=0; x<N ; x++)
            GP.M()(x,y) +=  (NRrandom3()-0.5) * N * 5e-2;
	}

    for (INT k=0 ; k<10 ; k++)
    {
      GP.amelior_sol();
    }
    BENCH_ASSERT(GP.ecart()<epsilon);
}
示例#12
0
static void 
globalmq_push(struct global_queue *q, struct cell * c) {
	uint32_t tail = GP(__sync_fetch_and_add(&q->tail,1));
	q->queue[tail] = c;
	__sync_synchronize();
	q->flag[tail] = true;
	__sync_synchronize();
}
示例#13
0
文件: sir.cpp 项目: Aleyasen/Alaki
void TEpidemModel::Plot(const TFltV& TrueV, const TStr& Label1, const TFltV& SimV, const TStr& Label2, const TStr& OutFNm, const TStr& Desc, const TStr& XLabel, const TStr& YLabel) {
  TGnuPlot GP(OutFNm, Desc);
  GP.AddPlot(TrueV, gpwLinesPoints, Label1);
  GP.AddPlot(SimV, gpwLinesPoints, Label2);
  GP.SetXYLabel(XLabel, YLabel);
  GP.SavePng();
  //GP.SaveEps(12);
}
示例#14
0
void ActorScroller::SetTransformFromReference( const LuaReference &ref )
{
	m_exprTransformFunction.SetFromReference( ref );

	// Probe to find which of the parameters are used.
#define GP(a,b)	m_exprTransformFunction.GetTransformCached( a, b, 2 )
	m_bFunctionDependsOnPositionOffset = (GP(0,0) != GP(1,0)) && (GP(0,1) != GP(1,1));
	m_bFunctionDependsOnItemIndex = (GP(0,0) != GP(0,1)) && (GP(1,0) != GP(1,1));
	m_exprTransformFunction.ClearCache();
}
示例#15
0
static void 
skynet_globalmq_push(struct message_queue * queue) {
	struct global_queue *q= Q;

	uint32_t tail = GP(__sync_fetch_and_add(&q->tail,1));
	q->queue[tail] = queue;
	__sync_synchronize();
	q->flag[tail] = true;
}
示例#16
0
/*
	http://blog.codingnow.com/2012/10/bug_and_lockfree_queue.html
	为了保证在进队列操作的时序。我们在原子递增队列尾指针后,还需要额外一个标记位指示数据已经被完整写入队列,
	这样才能让出队列线程取得正确的数据。
*/
static void 
skynet_globalmq_push(struct message_queue * queue) {
	struct global_queue *q= Q;

	uint32_t tail = GP(__sync_fetch_and_add(&q->tail,1));
	q->queue[tail] = queue; // 将这个消息放入全局队列
	__sync_synchronize();
	q->flag[tail] = true; // 标记这个位置 tail已经用过了 已经完全将这个消息队列 压入全局的消息队里中
}
示例#17
0
static void 
skynet_globalmq_push(struct message_queue * queue) {
	struct global_queue *q= Q;

	//uint32_t tail = GP(__sync_fetch_and_add(&q->tail,1));
	uint32_t tail = GP(::InterlockedIncrement(&q->tail)-1);
	q->queue[tail] = queue;
	//__sync_synchronize();
	::MemoryBarrier();
	q->flag[tail] = true;
}
示例#18
0
static struct cell * 
globalmq_pop(struct global_queue *q) {
	uint32_t head =  q->head;
	uint32_t head_ptr = GP(head);
	if (head_ptr == GP(q->tail)) {
		return NULL;
	}

	if(!q->flag[head_ptr]) {
		return NULL;
	}

	struct cell * c = q->queue[head_ptr];
	if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) {
		return NULL;
	}
	q->flag[head_ptr] = false;
	__sync_synchronize();

	return c;
}
示例#19
0
struct message_queue * 
skynet_globalmq_pop() {
	struct global_queue *q = Q;
    uint32_t head =  q->head;
    uint32_t head_ptr = GP(head);
    if (head_ptr == GP(q->tail)) {
        return NULL;
    }
    
	if(!q->flag[head_ptr]) {
        return NULL;
	}

    struct message_queue * mq = q->queue[head_ptr];
    if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) {
        return NULL;
    }
	q->flag[head_ptr] = false;

	return mq;
}
示例#20
0
bool CDefaultItem::LoadConfig()
{  
#ifdef _FILESYSTEM
  char* fileName = "defaultItem.txt";
  if (!IsFileExist(fileName, TXT_PATH))
    copyFile(fileName, TXT_PATH);
  string fullFilePath = getFilePath(fileName, TXT_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  char buffer[256];  
  ifstream in(fullFilePath);  
  if (! in.is_open())  
  { 
    cout << "Error opening file defaultItem"; 
    return false; 
  }
  int Line = 0;
  while (EOF != in.peek() )  
  { 
    in.getline (buffer,256);
    GParse GP(buffer);
    ItemRecord Item;
    Item.ItemId = GP.getInt();
    Item.ItemNum = GP.getInt();
    GSelfCtl->PushItem(Item);
  }
  return true;
#endif;
  /*
  char* fileName = "defaultItem.lua";
  if (!IsFileExist(fileName, LUA_PATH))
    copyFile(fileName, LUA_PATH);
  string fullFilePath = getFilePath(fileName, LUA_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  if (luaL_dofile(GLuaState, fullFilePath.c_str()))
  {
    CCLOG("defaultItem.lua file error!");
    return false;
  }
  CLuaObject LuaObject = CLuaObject("defaultItem", GLuaState);
  BEGIN_LUA(LuaObject)
  {
    ItemRecord Item;
    Item.ItemId = LuaObject.getInt("Item");
    Item.ItemNum = LuaObject.getInt("Num");
    GSelfCtl->PushItem(Item);
  }
  END_LUA(LuaObject)*/
  return true;
}
示例#21
0
bool CEliminateScore::LoadConfig()
{
#ifdef _FILESYSTEM
  char* fileName = "Score.txt";
  if (!IsFileExist(fileName, TXT_PATH))
    copyFile(fileName, TXT_PATH);
  string fullFilePath = getFilePath(fileName, TXT_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  char buffer[256];  
  ifstream in(fullFilePath);  
  if (! in.is_open())  
  { 
    cout << "Error opening file Score"; 
    return false; 
  }
  int Line = 0;
  while (EOF != in.peek() )  
  { 
    in.getline (buffer,256);
    GParse GP(buffer);
    ScoreTable ScoreT;
    ScoreT.Num = GP.getInt();
    ScoreT.Score = GP.getInt();
    Scores.push_back(ScoreT);
  }  
  return true;
#endif;
  /*
  char* fileName = "Score.lua";
  if (!IsFileExist(fileName, LUA_PATH))
    copyFile(fileName, LUA_PATH);
  string fullFilePath = getFilePath(fileName, LUA_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  if (luaL_dofile(GLuaState, fullFilePath.c_str()))
  {
    CCLOG("Score.lua file error!");
    return false;
  }
  CLuaObject LuaObject = CLuaObject("ScoreData", GLuaState);
  BEGIN_LUA(LuaObject)
  {
    ScoreTable ScoreT;
    ScoreT.Num = LuaObject.getInt("Num");
    ScoreT.Score = LuaObject.getInt("Score");
    Scores.push_back(ScoreT);
  }
  END_LUA(LuaObject)*/
  return true;
}
示例#22
0
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL VOID
check_SS
       	    	    	    		                         
IFN4(
	IU16, selector,	/* (I) 16-bit selector to stack segment */
	ISM32, privilege,	/* (I) privilege level to check against */
	IU32 *, descr_addr,	/* (O) address of stack segment descriptor */
	CPU_DESCR *, entry	/* (O) the decoded descriptor */
    )


   {
   /* must be within GDT or LDT */
   if ( selector_outside_GDT_LDT(selector, descr_addr) )
      GP(selector, FAULT_CHECKSS_SELECTOR);
   
   read_descriptor_linear(*descr_addr, entry);

   /* must be writable data */
   switch ( descriptor_super_type(entry->AR) )
      {
   case EXPANDUP_WRITEABLE_DATA:
   case EXPANDDOWN_WRITEABLE_DATA:
      break;          /* good type */
   
   default:
      GP(selector, FAULT_CHECKSS_BAD_SEG_TYPE);   /* bad type */
      }

   /* access check requires RPL == DPL == privilege */
   if ( GET_SELECTOR_RPL(selector) != privilege ||
	GET_AR_DPL(entry->AR) != privilege )
      GP(selector, FAULT_CHECKSS_ACCESS);

   /* finally it must be present */
   if ( GET_AR_P(entry->AR) == NOT_PRESENT )
      SF(selector, FAULT_CHECKSS_NOTPRESENT);

   }
示例#23
0
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GLOBAL ISM32
validate_TSS
       	    	    	                    
IFN3(
	IU16, selector,	/* (I) selector to be checked */
	IU32 *, descr_addr,	/* (O) address of related descriptor */
	BOOL, is_switch	/* (I) if true we are in task switch */
    )


   {
   BOOL is_ok = TRUE;
   IU8 AR;
   ISM32 super;

   /* must be in GDT */
   if ( selector_outside_GDT(selector, descr_addr) )
      {
      is_ok = FALSE;
      }
   else
      {
      /* is it really an available TSS segment (is_switch false) or
	 is it really a busy TSS segment (is_switch true) */
      AR = spr_read_byte((*descr_addr)+5);
      super = descriptor_super_type((IU16)AR);
      if ( ( !is_switch &&
	     (super == AVAILABLE_TSS || super == XTND_AVAILABLE_TSS) )
	   ||
           ( is_switch &&
	     (super == BUSY_TSS || super == XTND_BUSY_TSS) ) )
	 ;   /* ok */
      else
	 is_ok = FALSE;
      }
   
   /* handle invalid TSS */
   if ( !is_ok )
      {
      if ( is_switch )
	 TS(selector, FAULT_VALTSS_SELECTOR);
      else
	 GP(selector, FAULT_VALTSS_SELECTOR);
      }

   /* must be present */
   if ( GET_AR_P(AR) == NOT_PRESENT )
      NP(selector, FAULT_VALTSS_NP);

   return super;
   }
示例#24
0
eFlag Recoder::open(Sit S, const Str& enc, Bool toUTF8, CDesc& cd)
{
    GP(ConvInfo) newitem = new ConvInfo;
    (*newitem).method = ENC_NONE;
    (*newitem).physCD = NULL;
#ifdef HAVE_ICONV_H
    iconv_t icd = toUTF8 ? iconv_open("UTF-8", enc) : iconv_open(enc, "UTF-8");
    // switch off transliteration in iconv:
    // sadly non-standard, only works in windows port
    // int val = 0;
    // iconvctl(icd, ICONV_SET_TRANSLITERATE, &val);
    if (icd != (iconv_t) -1)
    {
        (*newitem).method = ENC_ICONV;
        (*newitem).physCD = (void *) icd;
    }
    else
#endif
    {
        // try to open internal recode
        void *physcd;
        physcd = encInternalOpen(enc, toUTF8);
        if (physcd != (void*)-1)
        {
            (*newitem).method = ENC_INTERNAL;
            (*newitem).physCD = physcd;
        }
        else
        {
            // try the encoding handler as a last resort
            void* enchlrUD = NULL;
            EncHandler *enchlr = NULL;
            if (S.getProcessor())
                enchlr = S.getProcessor() -> getEncHandler(&enchlrUD);
            if (enchlr)
            {
                void *physcd = enchlr -> open(enchlrUD, S.getProcessor(), toUTF8 ? EH_TO_UTF8 : EH_FROM_UTF8, enc);
                if (physcd != (void*) -1)
                {
                    (*newitem).method = ENC_HANDLER;
                    (*newitem).physCD = physcd;
                }
            }
        }
    };
    if ((*newitem).method != ENC_NONE)
        items.append(cd = newitem.keep());
    else
        Err1(S, E1_UNKNOWN_ENC, enc);
    return OK;
}
示例#25
0
eFlag Tree::insertAttSet(Sit S, XSLElement *tmpl)
{
    QName q; 
    Attribute *a;
    GP( QName ) sets = NULL;
    if (!!(a = tmpl -> atts.find(XSLA_NAME))) 
	E( tmpl -> setLogical(S, q, a -> cont, FALSE) );
    if (q.getLocal() != UNDEF_PHRASE && 
        attSets().findByName(q))
    {
	Str fullName;
	expandQStr(q, fullName);
	Err1(S, ET_DUPLICATE_ASET_NAME, fullName);
    };    
    attSets().append(new AttSet(q));
    return OK;
}
示例#26
0
bool CGlobleData::LoadConfig()
{
#ifdef _FILESYSTEM
  char* fileName = "GlobleData.txt";
  if (!IsFileExist(fileName, TXT_PATH))
    copyFile(fileName, TXT_PATH);
  string fullFilePath = getFilePath(fileName, TXT_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  char buffer[256];  
  ifstream in(fullFilePath);  
  if (! in.is_open())  
  { 
    cout << "Error opening file GlobleData"; 
    return false; 
  }
  while (EOF != in.peek() )  
  { 
    in.getline (buffer,256);
    GParse GP(buffer);
    string Key = GP.getString();
    int Value = GP.getInt();
    GlobleValue.insert(pair<string, int>(Key, Value));
  }
  GSelfCtl->_PlayerData._BulletNum = getValue("BulletNum");
  return true;
#endif;
  /*
  char* fileName = "GlobleData.lua";
  if (!IsFileExist(fileName, LUA_PATH))
    copyFile(fileName, LUA_PATH);
  string fullFilePath = getFilePath(fileName, LUA_PATH);
  int fileLen = strlen(fullFilePath.c_str());
  if (!fileLen)
    return false;
  if (luaL_dofile(GLuaState, fullFilePath.c_str()))
  {
    CCLOG("GlobleData.lua file error!");
    return false;
  }
  CLuaObject LuaObject = CLuaObject(GLuaState);
  int Num = LuaObject.getgInt("BlockToleNum");
  GSelfCtl->_PlayerData._BulletNum = LuaObject.getgInt("TotleBullet");*/
  return true;
}
示例#27
0
文件: gstat.cpp 项目: Accio/snap
void TGStatVec::Plot(const TGStatVal& XVal, const TGStatVal& YVal, const TStr& OutFNm, TStr& Desc, const TGpScaleTy& Scale,const bool& PowerFit) const {
  if (! Last()->HasVal(XVal) || ! Last()->HasVal(YVal)) {
    if (! Last()->HasVal(XVal)) { printf("** Does not have %s statistic\n", TGStat::GetValStr(XVal).CStr()); }
    if (! Last()->HasVal(YVal)) { printf("** Does not have %s statistic\n", TGStat::GetValStr(YVal).CStr()); }
    return;
  }
  if (Desc.Empty()) { Desc = OutFNm; }
  TFltPrV ValV;
  TGStatVec::GetValV(XVal, YVal, ValV);
  TGnuPlot GP(TStr::Fmt("%s-%s.%s", TGStat::GetValStr(XVal).CStr(), TGStat::GetValStr(YVal).CStr(), OutFNm.CStr()),
    TStr::Fmt("%s. %s vs. %s. G(%d,%d)", Desc.CStr(), TGStat::GetValStr(XVal).CStr(), TGStat::GetValStr(YVal).CStr(),
    Last()->GetNodes(), Last()->GetEdges()));
  GP.SetScale(Scale);
  GP.SetXYLabel(TGStat::GetValStr(XVal), TGStat::GetValStr(YVal));
  const int Id = GP.AddPlot(ValV, gpwLinesPoints);
  if (PowerFit) { GP.AddPwrFit(Id); }
  GP.SavePng();
}
示例#28
0
eFlag Tree::serializeNode(Sit S, Element *v, char *& result)
{
    OutputterObj out;
    OutputDefinition def;
    GP( DataLine ) targetLine = new DataLine;
    // set default options for output
    EQName xmlMethod;
    xmlMethod.setLocal((char*)"xml");
    E( def.setItemEQName(S, XSLA_METHOD, xmlMethod, NULL, OUTPUT_PRECEDENCE_WEAKEST) );
    E( def.setDefaults(S) ); 
    E( (*targetLine).open(S, (const char*)"arg:/dummy_", DLMODE_WRITE, NULL) );
    out.setOptions(S, targetLine, &def);
    E( (*v).serializeSubtree(S, out) );
    result = (*targetLine).getOutBuffer() -> compactToBuffer();
    E( (*targetLine).close(S) );
    targetLine.del();
    return OK;
}
示例#29
0
文件: sir.cpp 项目: Aleyasen/Alaki
void TSirSR2Model::Plot(const TStr& OutFNm, TStr Desc) const {
  if (OutValV.Empty()) { printf("EMPTY()");  return; }
  TFltV MV, BV;
  const TFltV& SMediaV = OutValV[2];
  for (int t=0; t < MediaV.Len(); t++) {
    if (t-T0 >= 0) { MV.Add(SMediaV[t-T0]); } else { MV.Add(0); }
  }
  const TFltV& SBlogV = OutValV[3];
  for (int t=0; t < BlogV.Len(); t++) {
    if (t-T0 >= 0) { BV.Add(SBlogV[t-T0]); } else { BV.Add(0); }
  }
  TGnuPlot GP(OutFNm, Desc+" "+GetStr());
  GP.AddPlot(MediaV, gpwLines, "TRUE MEDIA");
  GP.AddPlot(MV, gpwLinesPoints, "SIM MEDIA");
  GP.AddPlot(BlogV, gpwLines, "TRUE BLOGS");
  GP.AddPlot(BV, gpwLinesPoints, "SIM BLOGS");
  GP.SetXYLabel("Time [hours]", "Number of infected nodes");
  GP.SavePng();
}
示例#30
0
文件: hp.cpp 项目: yongwangCPH/peat
float Hp::calculate(vector<Atom*> atoms,
		    string assigned_parameters)
{

  /*** set vdw radii ***/
  if (assigned_parameters=="")
    {
      printf("No parameters have been set for atoms, using GP vdw distances\n");
      Generalparameters GP(rep);
      GP.set_vdw_radii(atoms);
    }

  float res = 0;
  float temp_result;

  Distances dist(rep);
  
  /*** find hydrophobic protein atoms ***/
  find_hydrophobic_atoms(atoms);
  
  for(unsigned int p=0; p<atoms.size(); p++)
    if(atoms[p]->is_hydrophobic)
      for(unsigned int l=0; l<p; l++)
	if(atoms[l]->is_hydrophobic)
	  {
	    temp_result = interaction(dist.calculate(atoms[p],atoms[l],true), atoms[p]->vdw_dist + atoms[l]->vdw_dist);
	    res += temp_result;
	            
	    printf("Hydrophobic atoms %s-%d and %s-%d at distance %f has interaction %f\n",
		   atoms[p]->element.c_str(),
		   p+1,
		   atoms[l]->element.c_str(),
		   l+1,
		   dist.calculate(atoms[p],atoms[l],true),
		   temp_result);
	  }
  

   
  return res;
}