logical OSyntaxHighlighter :: FindElements (QString qsText, int32 &riStart )
{
  logical                 term = NO;
  int                     iEnd = 0
                         ,iStart = riStart
                         ,iLength = 0;
  std::vector<SyntaxElement>::iterator it;
BEGINSEQ
  if(qsText.isEmpty())                               ERROR
  
  for ( it = elements.begin(); it != elements.end() && !term; ++it ){
    iStart = riStart;
    while ( iStart >= 0 )
      if(FindElement(qsText,iStart,(*it).rxStart)){
        iLength = (*it).rxStart.cap(0).length();
        iEnd = iStart+iLength;
        if((*it).isBlock)
          if(FindElement(qsText,iEnd,(*it).rxEnd)){ //highlight the block to the end of line
            iLength = (iEnd + (*it).rxStart.cap(0).length()) - iStart;
          }else{ // remember that the block doesnt end here
            iLength = qsText.length() - iStart;
            setCurrentBlockState(GetSyntaxElementIndex((*it)));
          }
        AddFormatRange((*it).syntaxclass,iStart,iLength);
        iStart+=iLength;
      }
  }


RECOVER
  term = YES;
ENDSEQ
  return term;
}
/*--------------------------------------------------------------------------------*/
bool TinyXMLADMData::TranslateXML(const std::string& data)
{
  TiXmlDocument doc;
  const TiXmlNode *node;
  bool success = false;

  DEBUG3(("XML: %s", data.c_str()));

  // dig to correct location of audioFormatExtended section
  doc.Parse(data.c_str());
  if ((node = FindElement(&doc, "ebuCoreMain")) != NULL)
  {
    if ((node = FindElement(node, "coreMetadata")) != NULL)
    {
      if ((node = FindElement(node, "format")) != NULL)
      {
        if ((node = FindElement(node, "audioFormatExtended")) != NULL)
        {
          CollectObjects(node);
                    
          success = true;
        }
        else ERROR("Failed to find audioFormatExtended element");
      }
      else ERROR("Failed to find format element");
    }
    else ERROR("Failed to find coreMetadata element");
  }
  else ERROR("Failed to find ebuCoreMain element");

  return success;
}
Exemple #3
0
/*----------------------------------------------------------------------------------------------
	Parameters:
		pszw: 16-bit key word to be added to the trie
----------------------------------------------------------------------------------------------*/
bool CTrieLevel::AddWord(wchar * pszw, COLORREF cr, BOOL fCaseMatters)
{
	AssertPtr(pszw);
	Assert(*pszw);

	int ite;
	wchar ch = fCaseMatters ? *pszw : towlower(*pszw);
	if (!(FindElement(ch, &ite)))
	{
		CTrieElement ** ppte = (CTrieElement **)realloc(m_ppte, sizeof(CTrieElement *) * ++m_cte);
		if (!ppte)
			return false;
		m_ppte = ppte;
		if (ite == -1)
			ite = 0;
		else
			memmove(&m_ppte[ite + 1], &m_ppte[ite], sizeof(CTrieElement *) * (m_cte - ite - 1));
		m_ppte[ite] = new CTrieElement(ch);
		if (!m_ppte[ite])
			return false;
		if (!m_ppte[ite]->CreateSubLevel())
			return false;
	}
	if (pszw[1] && !iswspace(pszw[1]))
		return m_ppte[ite]->m_ptlSub->AddWord(pszw + 1, cr, fCaseMatters);
	else
		m_ppte[ite]->m_ptlSub->m_cr = cr;
	return true;
}
void CXMLUtils::ExtractElementAll(const char     *szXML,
                                  const string  & strElementName,
                                  vector<string>& vOccurrences,
                                  bool            includeTag)
{
  while (1)
  {
    const char *szStartOuter = NULL, *szEndOuter = NULL, *szStartInner = NULL,
               *szEndInner   = NULL;

    if (!FindElement(szXML, strElementName, szStartOuter, szEndOuter,
                     szStartInner, szEndInner))
    {
      break;
    }

    if (includeTag)
    {
      vOccurrences.push_back(string(szStartOuter, szEndOuter - szStartOuter));
    }
    else
    {
      vOccurrences.push_back(string(szStartInner, szEndInner - szStartInner));
    }

    szXML = szEndOuter;
  }
}
string ControlFile::GetVirtualFilePath(const char *hardchipnr)
{
	errno_t err;
	FILE    * inFile;

	string  result = "";

	err = fopen_s(&inFile, (char *) filePath, "r");
	if (err != 0)
	{
		logError("Could not open file \"%s\" for reading (err = %d)", filePath, err);
		return result;
	}

	char content[MAX_CONTENT + 1];

	if (!seekToContentElement(inFile, "hardchipnr", hardchipnr))
	{
		fclose(inFile);
		return result;
	}

	FindElement(inFile, "file", content, MAX_CONTENT);
	result = content;

	fclose(inFile);

	return result;
}
Exemple #6
0
double Element::FindElementValueAsNumberConvertFromTo( const string& el,
                                                       const string& supplied_units,
                                                       const string& target_units)
{
  Element* element = FindElement(el);

  if (!element) {
    cerr << "Attempting to get non-existent element " << el << endl;
    exit(-1);
  }

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
      cerr << element->ReadFrom() << "Supplied unit: \""
           << supplied_units << "\" does not exist (typo?)." << endl;
      exit(-1);
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
      cerr << element->ReadFrom() << "Supplied unit: \""
           << supplied_units << "\" cannot be converted to " << target_units
           << endl;
      exit(-1);
    }
  }

  double value = element->GetDataAsNumber();
  if (!supplied_units.empty()) {
    value *= convert[supplied_units][target_units];
  }

  value = DisperseValue(element, value, supplied_units, target_units);

  return value;
}
BOOL CCfgFile::RemoveElement(LPCTSTR pGroup, LPCTSTR pElement)
{_STTEX();
	HGROUP hGroup = FindGroup( pGroup );
	LPCFGELEMENTINFO pcei = FindElement( hGroup, pElement );

	return RemoveElement( hGroup, pcei );
}
double Element::FindElementValueAsNumberConvertFromTo( string el,
                                                       string supplied_units,
                                                       string target_units)
{
  Element* element = FindElement(el);

  if (!element) {
    cerr << "Attempting to get non-existent element " << el << endl;
    exit(0);
  }

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
           << " conversion in FGXMLElement.cpp." << endl;
      exit(-1);
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
                   << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
      exit(-1);
    }
  }

  double value = element->GetDataAsNumber();
  if (!supplied_units.empty()) {
    value *= convert[supplied_units][target_units];
  }

  return value;
}
showType ControlFile::GetShowType()
{
	errno_t err;
	FILE    * inFile;

	err = fopen_s(&inFile, (char *) filePath, "r");
	if (err != 0)
	{
		logError("Could not open file \"%s\" for reading (err = %d)", filePath, err);
		return NON_SHOW_TYPE;
	}

	char content[MAX_ELEMENT + 1];

	bool result = FindElement(inFile, "show", content, MAX_ELEMENT);

	fclose(inFile);
	if (result)
	{
		string s = content;     //easier to use!
		if (s == "HIDE_VIRTUAL") return HIDE_VIRTUAL;
		else if (s == "HIDEREAL") return HIDEREAL;
		else if (s == "REAL_FIRST") return REAL_FIRST;
		else return REAL_LAST;
	}
	else
	{
		logError("Element <show> not found in control file \"%s\"", filePath);
		return REAL_LAST;
	}
}
// For cutting, collapse the crack if opened enough
// cods are hard coded and should be greater than traction law max cod
// Also won't collapse if this segment or a neighbor has traction law
// return tru unless collapsed position is out of the grid
bool CrackSegment::CollapseSurfaces(void)
{
	// make sure no traction on this segment or its neighbors
	if(MatID()>=0) return true;
	if(nextSeg!=NULL)
	{	if(nextSeg->MatID()>=0) return true;
	}
	if(prevSeg!=NULL)
	{	if(prevSeg->MatID()>=0) return true;
	}
	
	// check x and y opening
	double codx=fabs(surfx[0]-surfx[1]);
	double cody=fabs(surfy[0]-surfy[1]);
	if(codx>1.02 || cody>1.02)
	{	// OK to collapse
		x=(surfx[0]+surfx[1])/2.;
		y=(surfy[0]+surfy[1])/2.;
		if(!FindElement()) return false;
		surfx[0]=surfx[1]=x;
		surfy[0]=surfy[1]=y;
		surfInElem[0]=surfInElem[1]=planeInElem;
		SetMatID(-1);								// marks as collapsed
	}
	return true;
}
Exemple #11
0
void Failover::CreateXMLForUser( DataBaseAccess *dBA,const char *DIDInfo ,char * xmlData){
	vector<string> DID,UID,UName,UserName, Password,UserRole,Email, Mobile,Status;
	dBA->GetAllUserForDID(DIDInfo,&UID,&UName,&UserName,&Password,&UserRole,&Email,&Mobile,&Status);
	xml = new CMarkup();
		xml->OutOfElem();
					if ( !FindElement(xml->GetDoc(),"XMLDakshaImaging") )
						xml->AddElem( "XMLDakshaImaging" );
	for ( int i = 0 ; i < (int)UID.size() ; i++ ){
		CheckForXMLHeader("AddUser");
		xml->AddElem("UName",UName[i].c_str());
		xml->AddElem("UserName",UserName[i].c_str());
		xml->AddElem("Password",Password[i].c_str());
		xml->AddElem("UserRole",UserRole[i].c_str());
		xml->AddElem("Email",Email[i].c_str());
		xml->AddElem("ContactNo",Mobile[i].c_str());
		xml->AddElem("Status",Status[i].c_str());
		xml->OutOfElem();
	}

	for ( int i = 0 ; i < UID.size() ; i++ ){
			dBA->DeleteTableEntry("userugrouprelation","UID",atoi(UID[i].c_str()));
		}

	dBA->DeleteTableEntryForDID("userinfo", DIDInfo);
	string xml_Data = xml->GetDoc();
		sprintf ( xmlData,"%s",xml_Data.c_str());
}
Exemple #12
0
double Element::FindElementValueAsNumberConvertTo(const string& el, const string& target_units)
{
  Element* element = FindElement(el);

  if (!element) {
      std::stringstream error;
    error << ReadFrom() << "Attempting to get non-existent element " << el
         << endl;
    throw std::runtime_error(error.str());
  }

  string supplied_units = element->GetAttributeValue("unit");

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
        std::stringstream error;
      error << element->ReadFrom() << "Supplied unit: \""
           << supplied_units << "\" does not exist (typo?)." << endl;
      throw std::runtime_error(error.str());
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
        std::stringstream error;
      error << element->ReadFrom() << "Supplied unit: \""
           << supplied_units << "\" cannot be converted to " << target_units
           << endl;
      throw std::runtime_error(error.str());
    }
  }

  double value = element->GetDataAsNumber();

  // Sanity check for angular values
  if ((supplied_units == "RAD") && (fabs(value) > 2 * M_PI)) {
      cerr << element->ReadFrom() << "The value " << value
           << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]" << endl;
  }
  if ((supplied_units == "DEG") && (fabs(value) > 360.0)) {
      cerr << element->ReadFrom() << "The value " << value
           << " DEG is outside the range [ -360 DEG ; +360 DEG ]" << endl;
  }
  
  
  if (!supplied_units.empty()) {
    value *= convert[supplied_units][target_units];
  }

  if ((target_units == "RAD") && (fabs(value) > 2 * M_PI)) {
      cerr << element->ReadFrom() << "The value " << value
           << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]" << endl;
  }
  if ((target_units == "DEG") && (fabs(value) > 360.0)) {
      cerr << element->ReadFrom() << "The value " << value
           << " DEG is outside the range [ -360 DEG ; +360 DEG ]" << endl;
  }

  value = DisperseValue(element, value, supplied_units, target_units);

  return value;
}
Exemple #13
0
void TXmlStorage::RemoveIfExists(const UnicodeString & Name)
{
  tinyxml2::XMLElement * Element = FindElement(Name);
  if (Element != nullptr)
  {
    FCurrentElement->DeleteChild(Element);
  }
}
string Element::FindElementValue(string el)
{
  Element* element = FindElement(el);
  if (element) {
    return element->GetDataLine();
  } else {
    return "";
  }
}
void CGraphicsContainer::AddElement(IElementPtr pElement)
{	
	if(FindElement(pElement)>-1)
		return ;

	m_vecElements.push_back(pElement);

	ContainerChangedEvent(pElement);
}
HRESULT CVectorEx<TYPE>::RemoveElement(TYPE *pEl)
{
	LONG	lIndex = FindElement(pEl);

	if (0 > lIndex)
		return E_FAIL;
	
	return RemoveAt((DBORDINAL)lIndex);
} //CVectorEx<TYPE>::RemoveElement
int DeleteElement (SeqList *L, eleType e) {
	int position = FindElement(L, e);
	for (int i = position; i <= L->listLength - 1; i++) {
		L->data[i-1] = L->data[i];
	}
	L->data[L->listLength-1] = -1;
	L->listLength--;
	return 1;
}
double Element::FindElementValueAsNumber(string el)
{
  Element* element = FindElement(el);
  if (element) {
    return element->GetDataAsNumber();
  } else {
    cerr << "Attempting to get single data value from multiple lines" << endl;
    return 0;
  }
}
unsigned int Element::GetNumElements(string element_name)
{
  unsigned int number_of_elements=0;
  Element* el=FindElement(element_name);
  while (el) {
    number_of_elements++;
    el=FindNextElement(element_name);
  }
  return number_of_elements;
}
Exemple #20
0
bool TXmlStorage::ValueExists(const UnicodeString & Value) const
{
  bool Result = false;
  tinyxml2::XMLElement * Element = FindElement(Value);
  if (Element != nullptr)
  {
    Result = true;
  }
  return Result;
}
Exemple #21
0
bool TXmlStorage::DeleteValue(const UnicodeString & Name)
{
  bool Result = false;
  tinyxml2::XMLElement * Element = FindElement(Name);
  if (Element != nullptr)
  {
    FCurrentElement->DeleteChild(Element);
    Result = true;
  }
  return Result;
}
Exemple #22
0
void Failover::CheckForXMLHeader( const char * actionName ){

		xml->OutOfElem();
			if ( !FindElement(xml->GetDoc(),"XMLDakshaImaging") )
				xml->AddElem( "XMLDakshaImaging" );
			xml->IntoElem();
			xml->AddElem( "Action" );
			xml->AddAttrib("Name", actionName);
			xml->IntoElem();

}
int main()
{
    int M[NROWS][NCOLS] = {
        {0, 3, 7}, 
        {1, 4, 8}, 
        {5, 6, 9}, 
        {6, 8, 10}};
    
    PrintMatrix(M);

    int elem = 5;
    std::pair<int, int> p = FindElement(M, elem);
    std::cout << "Element " << elem << " is at [" << p.first << "," << 
        p.second << "]\n";    
    
    int elem2 = 2;
    std::pair<int, int> p2 = FindElement(M, elem2);
    std::cout << "Element " << elem2 << " is at [" << p2.first << "," << 
        p2.second << "]\n";    
}
Exemple #24
0
double Element::FindElementValueAsNumber(const string& el)
{
  Element* element = FindElement(el);
  if (element) {
    double value = element->GetDataAsNumber();
    value = DisperseValue(element, value);
    return value;
  } else {
    cerr << ReadFrom() << "Attempting to get non-existent element " << el
         << endl;
    exit(-1);
  }
}
Exemple #25
0
double Element::FindElementValueAsNumber(const string& el)
{
  Element* element = FindElement(el);
  if (element) {
    double value = element->GetDataAsNumber();
    value = DisperseValue(element, value);
    return value;
  } else {
      std::stringstream error;
    error << ReadFrom() << "Attempting to get non-existent element " << el
         << endl;
    throw std::runtime_error(error.str());
  }
}
Exemple #26
0
HRESULT SgmlElement::SetElementParameter(CString csNodeName, CString csParameter) {   
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    HRESULT hr = S_OK;

    SgmlElement *pElement = FindElement(csNodeName);
    if (pElement == NULL)
        hr = E_FAIL;

    if (SUCCEEDED(hr))
        pElement->SetParameter(csParameter);

    return hr;
}
Exemple #27
0
FGColumnVector3 Element::FindElementTripletConvertTo( const string& target_units)
{
  FGColumnVector3 triplet;
  Element* item;
  double value=0.0;
  string supplied_units = GetAttributeValue("unit");

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
        std::stringstream error;
      error << ReadFrom() << "Supplied unit: \""
           << supplied_units << "\" does not exist (typo?)." << endl;
      throw std::runtime_error(error.str());
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
        std::stringstream error;
      error << ReadFrom() << "Supplied unit: \""
           << supplied_units << "\" cannot be converted to " << target_units
           << endl;
      throw std::runtime_error(error.str());
    }
  }

  item = FindElement("x");
  if (!item) item = FindElement("roll");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
    triplet(1) = DisperseValue(item, value, supplied_units, target_units);
  } else {
    triplet(1) = 0.0;
  }
  

  item = FindElement("y");
  if (!item) item = FindElement("pitch");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
    triplet(2) = DisperseValue(item, value, supplied_units, target_units);
  } else {
    triplet(2) = 0.0;
  }

  item = FindElement("z");
  if (!item) item = FindElement("yaw");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
    triplet(3) = DisperseValue(item, value, supplied_units, target_units);
  } else {
    triplet(3) = 0.0;
  }

  return triplet;
}
Exemple #28
0
/*----------------------------------------------------------------------------------------------
	Parameters:
		prgwch: 16-bit key string to find
		cchLim: Length of prgwch
		pcch:   Will contain the length of the matched word if there is one.
			This can be NULL if the length is not needed. If it is not
			NULL, it should be initialized to 0 before the call.
----------------------------------------------------------------------------------------------*/
bool CTrieLevel::FindWord(wchar * prgwch, int cchLim, const char * pszDelim, COLORREF * pcr,
	int * pcch, BOOL fCaseMatters)
{
	AssertArray(prgwch, cchLim);
	AssertPtr(pcr);
	AssertPtr(pszDelim);
	int ite;

	*pcr = m_cr;
	if (!cchLim || !FindElement(fCaseMatters ? *prgwch : towlower(*prgwch), &ite))
		return m_cr != (COLORREF)-1;
	if (pcch)
		(*pcch)++;
	return m_ppte[ite]->m_ptlSub->FindWord(prgwch + 1, cchLim - 1, pszDelim, pcr, pcch, fCaseMatters);
}
Exemple #29
0
bool Xml::seekToContentElement(FILE * file, const char *element, const char *content) const
{
	if (file == NULL || element == NULL || content == NULL)
		return false;

	bool result;

	char content2[MAX_CONTENT + 1];

	do
	{
		result = FindElement(file, element, content2, MAX_CONTENT);
	} while (result && strcmp(content, content2) != 0);

	return result;
}
FGColumnVector3 Element::FindElementTripletConvertTo( string target_units)
{
  FGColumnVector3 triplet;
  Element* item;
  double value=0.0;
  string supplied_units = GetAttributeValue("unit");

  if (!supplied_units.empty()) {
    if (convert.find(supplied_units) == convert.end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" does not exist (typo?). Add new unit"
           << " conversion in FGXMLElement.cpp." << endl;
      exit(-1);
    }
    if (convert[supplied_units].find(target_units) == convert[supplied_units].end()) {
      cerr << endl << "Supplied unit: \"" << supplied_units << "\" cannot be converted to "
                   << target_units << ". Add new unit conversion in FGXMLElement.cpp or fix typo" << endl;
      exit(-1);
    }
  }

  item = FindElement("x");
  if (!item) item = FindElement("roll");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
  } else {
    value = 0.0;
    cerr << "Could not find an X triplet item for this column vector." << endl;
  }
  triplet(1) = value;

  item = FindElement("y");
  if (!item) item = FindElement("pitch");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
  } else {
    value = 0.0;
    cerr << "Could not find a Y triplet item for this column vector." << endl;
  }
  triplet(2) = value;

  item = FindElement("z");
  if (!item) item = FindElement("yaw");
  if (item) {
    value = item->GetDataAsNumber();
    if (!supplied_units.empty()) value *= convert[supplied_units][target_units];
  } else {
    value = 0.0;
    cerr << "Could not find a Z triplet item for this column vector." << endl;
  }
  triplet(3) = value;

  return triplet;
}