示例#1
0
void XDBF::injectStringEntry(wstring wstr, unsigned long long id)
{
    // if no id was provided, then we need to get the next available one
    if (id == 0)
        id = getNextId(ET_STRING);

    // create a character array to hold the data to write, we need to
    // make a copy so that we can reverse the endian of the wstring
    unsigned short *dataToWrite = new unsigned short[wstr.length() + 1];

    // copy the characters to the array
    for (int i = 0; i < wstr.length(); i++)
    {
        dataToWrite[i] = (unsigned short)wstr.at(i);
        SwapEndian(&dataToWrite[i], 1, 2);
    }

    dataToWrite[wstr.length()] = 0;

    // inject the new string entry
    injectEntry_private(ET_STRING, (char*)dataToWrite, WSTRING_BYTES(wstr.length()), id);

    // give the memory back
    delete[] dataToWrite;
}
示例#2
0
文件: CFont.cpp 项目: colinw7/CFont
CFont::
CFont(const CFont &font) :
 family_(font.family_), font_def_(font.font_def_), char_angle_(font.char_angle_),
 x_font_name_(font.x_font_name_)
{
  id_ = getNextId();
}
示例#3
0
mama_status
mamaTimeZone_create (mamaTimeZone*  timeZone)
{
    mamaTimeZoneImpl* impl;
    wList  tzList;

    wthread_static_mutex_lock (&sVector_mutex);

    tzList = getTimeZones();
    impl = list_allocate_element (tzList);
    if (!impl)
    {
        wthread_static_mutex_unlock (&sVector_mutex);
        return MAMA_STATUS_NOMEM;
    }
    else
    {
        impl->mInstanceId = getNextId();
        list_push_back (tzList, impl);
        if (!sThreadStarted)
            startThread();

        wthread_static_mutex_unlock (&sVector_mutex);

        *timeZone = (mamaTimeZone)impl;
        return MAMA_STATUS_OK;
    }
}
示例#4
0
irr::scene::ISceneNode *CIrrOdeWorld::cloneOdeNode(irr::scene::ISceneNode *pSource, irr::scene::ISceneNode *newParent, irr::scene::ISceneManager *newSmgr, s32 iNewId) {
    irr::scene::ISceneNode *pRet=pSource->clone(newParent,newSmgr);
    pRet->setID(iNewId==-1?getNextId():iNewId);
    pRet->setParent(newParent);

    return pRet;
}
示例#5
0
int createEmptyGarbledCircuit(GarbledCircuit *garbledCircuit, int n, int m,
		int q, int r, InputLabels inputLabels) {

    garbledCircuit->id = getNextId();
	garbledCircuit->garbledGates = (GarbledGate *) memalign(128,
			sizeof(GarbledGate) * q);
	garbledCircuit->garbledTable = (GarbledTable *) memalign(128,
			sizeof(GarbledTable) * q);
	garbledCircuit->wires = (Wire *) memalign(128, sizeof(Wire) * r);
	garbledCircuit->outputs = (int *) memalign(128, sizeof(int) * m);

	if (garbledCircuit->garbledGates == NULL
			|| garbledCircuit->garbledGates == NULL) {
		dbgs("Linux is a cheap miser that refuses to give us memory");
		exit(1);
	}
	garbledCircuit->m = m;
	garbledCircuit->n = n;
	garbledCircuit->q = q;
	garbledCircuit->r = r;
	int i;
	for (i = 0; i < r; i++) {
		garbledCircuit->wires[i].id = 0;
	}
	for (i = 0; i < q; i++) {
		garbledCircuit->garbledGates[i].id = 0;
	}

	for (i = 0; i < 2 * n; i += 2) {
		garbledCircuit->wires[i / 2].id = i + 1;
		garbledCircuit->wires[i / 2].label0 = inputLabels[i];
		garbledCircuit->wires[i / 2].label1 = inputLabels[i + 1];
	}
	return 0;
}
示例#6
0
文件: CFont.cpp 项目: colinw7/CFont
CFont::
CFont(const std::string &family, CFontStyle style, double size, double angle, double char_angle,
      int x_res, int y_res) :
 family_(family), font_def_(style, size, angle, x_res, y_res), char_angle_(char_angle)
{
  id_ = getNextId();
}
示例#7
0
    void CFGManager::readGroup(const string &group,
                               const YAML::Node &paramNodes) {
      unsigned int i, j;
      string type = "";
      cfgParamId newId = 0;

      for(i = 0; i < paramNodes.size(); ++i) {
        paramNodes[i]["type"] >> type;
        //cout << "Found type: " << type << endl;

        for(j = 0; j < dstNrOfParamTypes; ++j) {
          if( cfgParamTypeString[j] == type ) {
            break;
          }
        } // for
        CFGParam *param = NULL;
        switch (j) {
        case doubleParam :
          newId = getNextId();
          param = CFGParamDouble::createParam(newId, group, paramNodes[i]);
          insertParam(param);
          break;
        case intParam :
          newId = getNextId();
          param = CFGParamInt::createParam(newId, group, paramNodes[i]);
          insertParam(param);
          break;
        case boolParam :
          newId = getNextId();
          param = CFGParamBool::createParam(newId, group, paramNodes[i]);
          insertParam(param);
          break;
        case stringParam :
          newId = getNextId();
          param = CFGParamString::createParam(newId, group, paramNodes[i]);
          insertParam(param);
          break;
        default:
          // do nothing
          cout << "CFG: unknown type: " << type;
        } // switch
        if(newId != 0) {
          addedCFGParam(newId);
          newId = 0;
        }
      } // for
    }
示例#8
0
  int ExpressionFactory::generateXPression(const string &quant,const string &FSE){

    int id = getNextId();

    ParameterMap pm;


    if( quant == "mpi.mq.ob" ){

      XMap[id] = get_M_pm_sq_ob_Xpression(pm,false);

      if(FSE == "ob" )
	XMap[id] = XMap[id] + get_M_pm_sq_ob_FSE_Xpression( pm );
      else if( FSE == "tmFS" )
	XMap[id] = XMap[id] * pow( 1 + get_tm_FSE_Rpm( pm ) , 2 );

      PMMap[id] = pm;

    } else if( quant == "fpi.mq.ob" ){

      XMap[id] = get_f_pm_ob_Xpression(pm,false);

      if(FSE == "ob" )
	XMap[id] = XMap[id] + get_f_pm_ob_FSE_Xpression( pm );
      else  if(FSE == "tmFS" )
	XMap[id] = XMap[id] * ( 1 +  get_tm_FSE_Rfpm( pm  ) );


      PMMap[id] = pm;
    } else if( quant == "mpi_0.mq.ob" ){

      XMap[id] = get_M_0_sq_ob_Xpression(pm,false);

      if(FSE == "ob" )
	XMap[id] = XMap[id] + get_M_0_sq_ob_FSE_Xpression( pm );
      else  if(FSE == "tmFS" )
	XMap[id] = XMap[id] * pow( 1 +  get_tm_FSE_RM0( pm ) , 2 );


      PMMap[id] = pm;
    } else  if( quant == "ob.FSE.mpm" ) {
      XMap[id] =  get_M_pm_sq_ob_FSE_Xpression( pm ) ;
      PMMap[id] = pm;
    } else  if( quant == "ob.FSE.fpm" ) {
      XMap[id] = get_f_pm_ob_FSE_Xpression( pm );
      PMMap[id] = pm;
    } else  if( quant == "tmFS.mpm" ) {
      XMap[id] =  1. + 2. * get_tm_FSE_Rpm( pm );
      PMMap[id] = pm;
    } else  if( quant == "tmFS.fpm" ) {
      XMap[id] = 1. +  get_tm_FSE_Rfpm( pm );
      PMMap[id] = pm;
    }



    return id;
  }
示例#9
0
/*! Add a new character.
 */
QDomElement VondelBook::addNewCharacter(QString name)
{
    QDomElement character = vondelDOM->createElement(VondelBook::XML_CHARACTER);
    addCreationDate(character);
    int id = getNextId(chaptersList);
    character.setAttribute(VondelBook::XML_ID, id);
    character.setAttribute(VondelBook::XML_NAME, name);
    charactersList.appendChild(character);
    return character;
}
示例#10
0
XAP_Dialog_Id XAP_DialogFactory::registerDialog(XAP_Dialog *(* pStaticConstructor)(XAP_DialogFactory *, XAP_Dialog_Id id),XAP_Dialog_Type iDialogType)
{
	_dlg_table * pDlgTable = new _dlg_table;
	pDlgTable->m_id = getNextId();
	pDlgTable->m_type = iDialogType;
	pDlgTable->m_pfnStaticConstructor = pStaticConstructor;
	pDlgTable->m_tabbed = FALSE;
	m_vec_dlg_table.addItem(pDlgTable);
	m_vecDynamicTable.addItem(pDlgTable);
	return pDlgTable->m_id;
}
示例#11
0
bool SpatialAreaStore::insertArea(Area *a)
{
	if (a->id == U32_MAX)
		a->id = getNextId();
	if (!areas_map.insert(std::make_pair(a->id, *a)).second)
		// ID is not unique
		return false;
	m_tree->insertData(0, nullptr, get_spatial_region(a->minedge, a->maxedge), a->id);
	invalidateCache();
	return true;
}
示例#12
0
 cfgParamId CFGManager::createParam(const string &_group, const string &_name,
                                    const cfgParamType &_paramType) {
   if( (_group != "") && (_name != "") ) {
     cfgParamId newId;
     newId = getParamId(_group, _name);
     if( newId != 0 ) {
       return newId;
     } else {
       CFGParam *param = NULL;
       switch (_paramType) {
       case doubleParam :
         newId = getNextId();
         param = (CFGParam*) (new CFGParamDouble(newId, _group, _name));
         insertParam(param);
         break;
       case intParam :
         newId = getNextId();
         param = (CFGParam*) (new CFGParamInt(newId, _group, _name));
         insertParam(param);
         break;
       case boolParam :
         newId = getNextId();
         param = (CFGParam*) (new CFGParamBool(newId, _group, _name));
         insertParam(param);
         break;
       case stringParam :
         newId = getNextId();
         param = (CFGParam*) (new CFGParamString(newId, _group, _name));
         insertParam(param);
         break;
       default :
         newId = 0;
       } // switch
       if(newId != 0) {
         addedCFGParam(newId);
       }
       return newId;
     }
   }
   return 0;
 }
示例#13
0
void FilePoller::init(std::chrono::milliseconds pollInterval) {
  auto context = contextSingleton.try_get();
  if (!context) {
    LOG(ERROR) << "Poller context requested after destruction.";
    return;
  }
  pollerId_ = context->getNextId();
  context->getScheduler().addFunction(
      [this] { this->checkFiles(); },
      pollInterval,
      folly::to<std::string>(pollerId_));
}
示例#14
0
文件: CFont.cpp 项目: colinw7/CFont
CFont::
CFont(const std::string &full_name) :
 x_font_name_(full_name)
{
  uint isize;

  decodeXFontName(full_name, family_, font_def_.style, isize, font_def_.x_res, font_def_.y_res);

  font_def_.size  = isize;
  font_def_.angle = 0;

  id_ = getNextId();
}
示例#15
0
bool VectorAreaStore::insertArea(Area *a)
{
	if (a->id == U32_MAX)
		a->id = getNextId();
	std::pair<AreaMap::iterator, bool> res =
			areas_map.insert(std::make_pair(a->id, *a));
	if (!res.second)
		// ID is not unique
		return false;
	m_areas.push_back(&res.first->second);
	invalidateCache();
	return true;
}
void VMapFactory::preventSpellsFromBeingTestedForLoS(
		const char* pSpellIdString) {
	if (!iIgnoreSpellIds)
		iIgnoreSpellIds = new Table<unsigned int, bool>();
	if (pSpellIdString != NULL) {
		unsigned int pos = 0;
		unsigned int id;
		std::string confString(pSpellIdString);
		chompAndTrim(confString);
		while (getNextId(confString, pos, id)) {
			iIgnoreSpellIds->set(id, true);
		}
	}
}
示例#17
0
AbstractModule *ModuleManager::create (const QString &type, const QString &name) {
    if (get (name)) { // name already exists
        return NULL;
    }

    if (registry.contains (type)) {
        AbstractModule *m = (*registry.value (type).fac) (getNextId (), name);
        m->setTypeName (type);
        items->push_back (m);
        emit moduleAdded (m);
        return m;
    } else
        return NULL;
}
示例#18
0
/// Add a new chapter to the book.
QDomElement VondelBook::addNewChapter(QString title)
{
    QDomElement chapter = vondelDOM->createElement(VondelBook::XML_CHAPTER);

    if (title == "") title = QObject::tr("Untitled Chapter");
    chapter.setAttribute(VondelBook::XML_TITLE, title);
    addCreationDate(chapter);

    int id = getNextId(chaptersList);
    chapter.setAttribute(VondelBook::XML_ID, id);

    chaptersList.appendChild(chapter);
    return chapter;
}
示例#19
0
void XDBF::injectAchievementEntry(Achievement_Entry *entry, unsigned long long id)
{
    int nameLen = WSTRING_BYTES(entry->name->size());
    int lockedDescLen = WSTRING_BYTES(entry->lockedDescription->size());
    int unlockedDescLen = WSTRING_BYTES(entry->unlockedDescription->size());

    if (id == 0)
        entry->id = id = getNextId(ET_ACHIEVEMENT);
    if (entry->imageID == 0)
        entry->imageID = getNextId(ET_IMAGE);

    entry->size = 0x1C;

    char *data = new char[0x1C + nameLen + lockedDescLen + unlockedDescLen];
    wchar_t *nameCpy = new wchar_t[entry->name->size() + 1];
    wchar_t *lockedDescCpy = new wchar_t[entry->lockedDescription->size() + 1];
    wchar_t *unlockedDescCpy = new wchar_t[entry->unlockedDescription->size() + 1];

    memcpy(nameCpy, entry->name->c_str(), nameLen);
    memcpy(lockedDescCpy, entry->lockedDescription->c_str(), lockedDescLen);
    memcpy(unlockedDescCpy, entry->unlockedDescription->c_str(), unlockedDescLen);

    swapAchievementEndianness(entry);
    memcpy(data, &entry->size, 0x1C);
    swapAchievementEndianness(entry);

    SwapEndianUnicode(nameCpy, nameLen);
    SwapEndianUnicode(lockedDescCpy, lockedDescLen);
    SwapEndianUnicode(unlockedDescCpy, unlockedDescLen);

    memcpy(&data[0x1C], nameCpy, nameLen);
    memcpy(&data[0x1C + nameLen], unlockedDescCpy, unlockedDescLen);
    memcpy(&data[0x1C + nameLen + unlockedDescLen], lockedDescCpy, lockedDescLen);

    injectEntry_private(ET_ACHIEVEMENT, data, 0x1C + nameLen + lockedDescLen + unlockedDescLen, id);
}
示例#20
0
/**
 Add a new scene to a chapter.
*/
QDomElement VondelBook::addNewScene(QDomElement chapter, QString title)
{
    QString chapterId;
    int id = getNextId(scenesList);
    if (title == "") title = QObject::tr("Untitled Scene ") + QString::number(id);

    VondelScene *scene = addScene(id, title);

    scenesList.appendChild(scene->xmlNode);
    chapterId = chapter.attribute(VondelBook::XML_ID);
    scene->xmlNode.setAttribute(XML_ID, id);
    scene->xmlNode.setAttribute(XML_CHAPTERID, chapterId);
    addCreationDate(scene->xmlNode);

    return scene->xmlNode;
}
示例#21
0
AbstractInterface *InterfaceManager::create (const QString &type, const QString &name) {
    if (get (name)) { // name already exists
        return NULL;
    }

    if (registry_.contains (type)) {
        AbstractInterface *i = (*registry_.value (type).fac) (getNextId (), name);
        i->setTypeName (type);
        if (items_->empty ()) // this is the first interface, make it the main interface
            setMainInterface (i);
        items_->push_back (i);
        emit interfaceAdded (i);
        return i;
    } else {
        return NULL;
    }
}
示例#22
0
bool Registry::registerTrackerType(std::string name,
                                   std::shared_ptr<NewTrackerFactory> f) {
    if (m_typeByString.find(name) != m_typeByString.end()) {
        //throw std::invalid_argument("Tracker with same name already registered");
        Q_EMIT trackerIsAlreadyLoaded(name);
        return false;
    } else {
        const TrackerType type = getNextId();
        m_typeByString.emplace(name, type);
        m_stringByType.emplace(type, name);
        m_trackerByType.emplace(type, f);

        Q_EMIT newTracker(type);

        return true;
    }
}
示例#23
0
void Pathfinder::inputPlace()
{
	string name;
	int id;
	string longitude;
	string lattitude;
	int elevation;
	flushall();
	cout << "Enter a new place!\nName:";
	getline(cin, name);
	cout << "Longitude";
	getline(cin, longitude);
	cout << "Lattitude:";
	getline(cin, lattitude);
	cout << "Elevation (feet):";
	cin >> elevation;
	
	place *p = new place(name, lattitude, longitude, elevation, getNextId());

	places.push_back(p);
}
示例#24
0
文件: todo.c 项目: reuteran/todo-list
void insertItem(char *argv[],int argc)
{


	//Assemble item description
	char desc_c[MAX_DESC_LEN];
	strcpy(desc_c,argv[2]);
	int i;
	for(i = 3;i<argc;i++){
		strcat(desc_c," ");
		strcat(desc_c,argv[i]);
	}

	unsigned int id = getNextId();
	if(!id){
		//printf("List is full, delete an item before adding a new one\n");
		quit("List is full, delete an item before adding a new one\n");
	}


	FILE *file = fopen(FILENAME,"a");
	if(!file){
		quit("Error opening file");
	}



	char buffer[strlen(desc_c)+1];
	strcpy(buffer,desc_c);

	if(fprintf(file, "%u %s\n",id,buffer) < 0){
//		ids[id-1] = 0;
		quit("Error writing to file");
	}
	

	fclose(file);

}
示例#25
0
int addSongToPlaylist(FILE * fp, Song * song) {
	if(playlist.length==playlist_max_length) {
		commandError(fp, ACK_ERROR_PLAYLIST_MAX,
                                "playlist is at the max size", NULL);
		return -1;
	}

	if(playlist_state==PLAYLIST_STATE_PLAY) {
		if(playlist.queued>=0 && playlist.current==playlist.length-1) {
			lockPlaylistInteraction();
			clearPlayerQueue();
			unlockPlaylistInteraction();
		}
	}

	playlist.songs[playlist.length] = song;
	playlist.songMod[playlist.length] = playlist.version;
	playlist.order[playlist.length] = playlist.length;
	playlist.positionToId[playlist.length] = getNextId();
	playlist.idToPosition[playlist.positionToId[playlist.length]] = playlist.length;
	playlist.length++;

	if(playlist.random) {
		int swap;
		int start;
		/*if(playlist_state==PLAYLIST_STATE_STOP) start = 0;
		else */if(playlist.queued>=0) start = playlist.queued+1;
		else start = playlist.current+1;
                if(start < playlist.length) {
		        swap = random()%(playlist.length-start);
		        swap+=start;
		        swapOrder(playlist.length-1,swap);
                }
	}
	
	incrPlaylistVersion();

	return 0;
}
bool IE_Exp_OpenXML_Listener::populate(fl_ContainerLayout* /* sfh */, const PX_ChangeRecord* pcr)
{	
	switch (pcr->getType())
	{
		case PX_ChangeRecord::PXT_InsertSpan:
		{
			const PX_ChangeRecord_Span* pcrs = static_cast<const PX_ChangeRecord_Span*>(pcr);
			PT_BufIndex buffer = pcrs->getBufIndex();
			const UT_UCSChar* pData = pdoc->getPointer(buffer);		

			if(*pData == UCS_FF)
			{
				paragraph->setPageBreak();
				return true;
			}

			UT_UCS4String str(pData, pcrs->getLength());
			OXML_SharedElement shared_element_text(new OXML_Element_Text(str.utf8_str(), str.length()));

			OXML_Element_Run* element_run = new OXML_Element_Run(getNextId());
			OXML_SharedElement shared_element_run(static_cast<OXML_Element*>(element_run));

			//add run properties 
			PT_AttrPropIndex api = pcr->getIndexAP();			
			const PP_AttrProp* pAP = NULL;
			bool bHaveProp = pdoc->getAttrProp(api,&pAP);

			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();
				
				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						if(element_run->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}
			}
			
			if(bInHyperlink)
			{
				//make sure hyperlinks are blue and underlined
				if(element_run->setProperty("text-decoration", "underline") != UT_OK)
					return false;
				if(element_run->setProperty("color", "0000FF") != UT_OK) 
					return false;
				if(hyperlink->appendElement(shared_element_run) != UT_OK)
					return false;
			}
			else
			{
				if(paragraph->appendElement(shared_element_run) != UT_OK)
					return false;
			}
			return element_run->appendElement(shared_element_text) == UT_OK;
		}
		case PX_ChangeRecord::PXT_InsertObject:
		{
			const PX_ChangeRecord_Object * pcro = static_cast<const PX_ChangeRecord_Object *> (pcr);
			PT_AttrPropIndex api = pcr->getIndexAP();			
			const PP_AttrProp* pAP = NULL;
			bool bHaveProp = pdoc->getAttrProp(api,&pAP);

			const gchar* szValue;
			const gchar* szName;

			switch (pcro->getObjectType())
			{
				case PTO_Field:
				{
					fd_Field* field = pcro->getField();
					
					switch(field->getFieldType())
					{
						case fd_Field::FD_ListLabel:
						{

							OXML_Element_List* element_list = new OXML_Element_List(getNextId(), paragraph);
							OXML_SharedElement shared_element_list(static_cast<OXML_Element*>(element_list));

							if(bHaveProp && pAP)
							{
								size_t propCount = pAP->getPropertyCount();
				
								size_t i;
								for(i=0; i<propCount; i++)
								{
									if(pAP->getNthProperty(i, szName, szValue))
									{
										//TODO: Take the debug message out when we are done
										UT_DEBUGMSG(("List Property %s=%s\n", szName, szValue));
										if(element_list->setProperty(szName, szValue) != UT_OK)
											return false;		
									}
								}

								size_t attrCount = pAP->getAttributeCount();

								for(i=0; i<attrCount; i++)
								{
									if(pAP->getNthAttribute(i, szName, szValue))
									{
										//TODO: Take the debug message out when we are done
										UT_DEBUGMSG(("List Attribute: %s=%s\n", szName, szValue));	
										if(element_list->setAttribute(szName, szValue) != UT_OK)
											return false;		
									}
								}
							}

							return paragraph->appendElement(shared_element_list) == UT_OK;			
						}
						
						default:
						{
							UT_UTF8String value = field->getValue(); // getValue() can return NULL
							OXML_Element_Field* element_field = new OXML_Element_Field(getNextId(), field->getFieldType(), value.utf8_str());
							OXML_SharedElement shared_element_field(static_cast<OXML_Element*>(element_field));

							if(bHaveProp && pAP)
							{
								size_t propCount = pAP->getPropertyCount();
				
								size_t i;
								for(i=0; i<propCount; i++)
								{
									if(pAP->getNthProperty(i, szName, szValue))
									{
										//TODO: Take the debug message out when we are done
										UT_DEBUGMSG(("Field Property %s=%s\n", szName, szValue));
										if(element_field->setProperty(szName, szValue) != UT_OK)
											return false;		
									}
								}

								size_t attrCount = pAP->getAttributeCount();

								for(i=0; i<attrCount; i++)
								{
									if(pAP->getNthAttribute(i, szName, szValue))
									{
										//TODO: Take the debug message out when we are done
										UT_DEBUGMSG(("Field Attribute: %s=%s\n", szName, szValue));	
										if(element_field->setAttribute(szName, szValue) != UT_OK)
											return false;		
									}
								}
							}

							return paragraph->appendElement(shared_element_field) == UT_OK;			
						}
						
					}		
				}

				case PTO_Hyperlink:
				{
					if(bInHyperlink)
					{
						bInHyperlink = false;
						return true;
					}

					bInHyperlink = true;

					hyperlink = new OXML_Element_Hyperlink(getNextId());
					OXML_SharedElement shared_element_hyperlink(static_cast<OXML_Element*>(hyperlink));

					if(bHaveProp && pAP)
					{
						size_t propCount = pAP->getPropertyCount();
				
						size_t i;
						for(i=0; i<propCount; i++)
						{
							if(pAP->getNthProperty(i, szName, szValue))
							{
								//TODO: Take the debug message out when we are done
								UT_DEBUGMSG(("Hyperlink Property %s=%s\n", szName, szValue));
								if(hyperlink->setProperty(szName, szValue) != UT_OK)
									return false;		
							}
						}

						size_t attrCount = pAP->getAttributeCount();

						for(i=0; i<attrCount; i++)
						{
							if(pAP->getNthAttribute(i, szName, szValue))
							{
								//TODO: Take the debug message out when we are done
								UT_DEBUGMSG(("Hyperlink Attribute: %s=%s\n", szName, szValue));	
								if(hyperlink->setAttribute(szName, szValue) != UT_OK)
									return false;		
							}
						}
					}

					return paragraph->appendElement(shared_element_hyperlink) == UT_OK;
				}

				case PTO_Image:			
				{
					OXML_Element_Run* element_run = new OXML_Element_Run(getNextId());
					OXML_SharedElement shared_element_run(static_cast<OXML_Element*>(element_run));

					if(paragraph->appendElement(shared_element_run) != UT_OK)
						return false;

					OXML_Element_Image* element_image = new OXML_Element_Image(getNextId());
					OXML_SharedElement shared_element_image(static_cast<OXML_Element*>(element_image));					

					if(bHaveProp && pAP)
					{
						size_t propCount = pAP->getPropertyCount();
				
						size_t i;
						for(i=0; i<propCount; i++)
						{
							if(pAP->getNthProperty(i, szName, szValue))
							{
								//TODO: Take the debug message out when we are done
								UT_DEBUGMSG(("Image Property %s=%s\n", szName, szValue));
								if(element_image->setProperty(szName, szValue) != UT_OK)
									return false;		
							}
						}

						size_t attrCount = pAP->getAttributeCount();

						for(i=0; i<attrCount; i++)
						{
							if(pAP->getNthAttribute(i, szName, szValue))
							{
								//TODO: Take the debug message out when we are done
								UT_DEBUGMSG(("Image Attribute: %s=%s\n", szName, szValue));	
								if(element_image->setAttribute(szName, szValue) != UT_OK)
									return false;		
							}
						}
					}
					return element_run->appendElement(shared_element_image) == UT_OK;
				}

				case PTO_Bookmark:
				{
					if(bHaveProp && pAP)
					{
						if(!pAP->getAttribute("name", szValue))
						{
							UT_DEBUGMSG(("FRT:OpenXML exporter bookmark without name attribute\n"));
							return true;
						}
						std::string bookmarkName(szValue);

						if(!pAP->getAttribute("type", szValue))
						{
							UT_DEBUGMSG(("FRT:OpenXML exporter bookmark without type attribute\n"));
							return true;
						}
						std::string bookmarkType(szValue);

						std::string bookmarkId("");
						if(!bookmarkType.compare("start"))
						{
							bookmarkId = getNextId();
							document->setBookmarkName(bookmarkId, bookmarkName);
						}
						else if(!bookmarkType.compare("end"))
						{
							bookmarkId = document->getBookmarkId(bookmarkName);
						}
						else
						{
							UT_DEBUGMSG(("FRT:OpenXML exporter bookmark with invalid type attribute=%s\n", bookmarkType.c_str()));
							return true;
						}							

						OXML_Element_Bookmark* bookmark = new OXML_Element_Bookmark(bookmarkId);
						bookmark->setName(bookmarkId);
						OXML_SharedElement shared_element_bookmark(static_cast<OXML_Element*>(bookmark));

						size_t propCount = pAP->getPropertyCount();
				
						size_t i;
						for(i=0; i<propCount; i++)
						{
							if(pAP->getNthProperty(i, szName, szValue))
							{
								//TODO: Take the debug message out when we are done
								UT_DEBUGMSG(("Bookmark Property %s=%s\n", szName, szValue));
								if(bookmark->setProperty(szName, szValue) != UT_OK)
									return false;		
							}
						}

						size_t attrCount = pAP->getAttributeCount();

						for(i=0; i<attrCount; i++)
						{
							if(pAP->getNthAttribute(i, szName, szValue))
							{
								//TODO: Take the debug message out when we are done
								UT_DEBUGMSG(("Bookmark Attribute: %s=%s\n", szName, szValue));	
								if(bookmark->setAttribute(szName, szValue) != UT_OK)
									return false;		
							}
						}
						return paragraph->appendElement(shared_element_bookmark) == UT_OK;
					}
					return true;
				}
				default:
					return true;
			}

		}
		case PX_ChangeRecord::PXT_InsertFmtMark:
		default:
			return true;
	}
	return true;
}
bool IE_Exp_OpenXML_Listener::populateStrux(pf_Frag_Strux* sdh, const PX_ChangeRecord* pcr , fl_ContainerLayout** /* psfh */)
{
	if(pcr->getType() != PX_ChangeRecord::PXT_InsertStrux)
		return false;

	const PX_ChangeRecord_Strux* pcrx = static_cast<const PX_ChangeRecord_Strux *> (pcr);

	PT_AttrPropIndex api = pcr->getIndexAP();			
	const PP_AttrProp* pAP = NULL;
	bool bHaveProp = pdoc->getAttrProp(api,&pAP);

	switch (pcrx->getStruxType())
	{
		case PTX_Section:
		{
			section = new OXML_Section();
			section->setTarget(TARGET_DOCUMENT);
			OXML_SharedSection shared_section(section);

			//add section properties 
			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Section Property: %s=%s\n", szName, szValue));	
						if(section->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Section Attribute: %s=%s\n", szName, szValue));	
						if(section->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}
			}

			return document->appendSection(shared_section) == UT_OK;
		}
		case PTX_Block:
		{
			paragraph = new OXML_Element_Paragraph(getNextId());
			OXML_SharedElement shared_paragraph(static_cast<OXML_Element*>(paragraph));

			//add paragraph properties 
			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						if(paragraph->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						if(paragraph->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}
			}
			
			if(!m_cellStack.empty())
			{
				OXML_Element_Cell* cell = m_cellStack.top();
				return cell->appendElement(shared_paragraph) == UT_OK;
			}
			else if(bInTextbox)
				return textbox->appendElement(shared_paragraph) == UT_OK;

			return section->appendElement(shared_paragraph) == UT_OK;
		}
		case PTX_SectionHdrFtr:
        {
			section = new OXML_Section(getNextId());
			OXML_SharedSection shared_section(static_cast<OXML_Section*>(section));

			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Header/Footer Property: %s=%s\n", szName, szValue));	
						if(section->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Header/Footer Attribute: %s=%s\n", szName, szValue));	
						if(section->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}

				if(pAP->getAttribute("type", szValue))
				{
					if(strstr(szValue, "header"))
					{
						section->setTarget(TARGET_HEADER);
						return document->addHeader(shared_section) == UT_OK;
					}
					else if(strstr(szValue, "footer"))
					{
						section->setTarget(TARGET_FOOTER);
						return document->addFooter(shared_section) == UT_OK;
					}
				}				
			}
			return true;			
		}
		case PTX_SectionEndnote:
        {
			savedSection = section; //save the current section
			savedParagraph = paragraph; //save the current paragraph

			section = new OXML_Section(getNextId());
			OXML_SharedSection shared_section(static_cast<OXML_Section*>(section));

			section->setTarget(TARGET_ENDNOTE);

			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Endnote Property: %s=%s\n", szName, szValue));	
						if(section->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Endnote Attribute: %s=%s\n", szName, szValue));	
						if(section->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}
			}

			return document->addEndnote(shared_section) == UT_OK;
		}
		case PTX_SectionTable:
		{	
			OXML_Element_Table* table = new OXML_Element_Table(getNextId());
			OXML_SharedElement shared_table(static_cast<OXML_Element*>(table));

			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Table Property: %s=%s\n", szName, szValue));	
						if(table->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Table Attribute: %s=%s\n", szName, szValue));	
						if(table->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}
			}
			tableHelper.OpenTable(sdh, pcr->getIndexAP());

			bool tableInTable = !m_tableStack.empty();
			m_tableStack.push(table);

			if(tableInTable)
			{
				//this is a table inside another table
				OXML_Element_Cell* cell = m_cellStack.top();
				return cell->appendElement(shared_table) == UT_OK;
			}

			return section->appendElement(shared_table) == UT_OK;
		}
		case PTX_SectionCell:
		{
			OXML_Element_Table* table = NULL;
			if(!m_tableStack.empty())
				table = m_tableStack.top();

			if(!table)
			{
				UT_DEBUGMSG(("FRT: OpenXML exporter corrupted table layout. Invalid Cell Open."));
				return false;
			}

			OXML_Element_Row* row = NULL;
			if(!m_rowStack.empty())
				row = m_rowStack.top();

			tableHelper.OpenCell(api);
			UT_sint32 left = tableHelper.getLeft();
			UT_sint32 right = tableHelper.getRight();
			UT_sint32 top = tableHelper.getTop();
			UT_sint32 bottom = tableHelper.getBot();

			if(!row || tableHelper.isNewRow())
			{
				row = new OXML_Element_Row(getNextId(), table);
				m_rowStack.push(row);
				row->setNumCols(tableHelper.getNumCols());
				OXML_SharedElement shared_row(static_cast<OXML_Element*>(row));
				if(table->appendElement(shared_row) != UT_OK)
					return false;
			}

			OXML_Element_Cell* cell = new OXML_Element_Cell(getNextId(), table, row, left, right, top, bottom);
			m_cellStack.push(cell);
			OXML_SharedElement shared_cell(static_cast<OXML_Element*>(cell));

			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Cell Property: %s=%s\n", szName, szValue));	
						if(cell->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Cell Attribute: %s=%s\n", szName, szValue));	
						if(cell->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}
			}
					
			return row->appendElement(shared_cell) == UT_OK;
		}
		case PTX_SectionFootnote:
        {
			savedSection = section; //save the current section
			savedParagraph = paragraph; //save the current paragraph

			section = new OXML_Section(getNextId());
			OXML_SharedSection shared_section(static_cast<OXML_Section*>(section));

			section->setTarget(TARGET_FOOTNOTE);
			
			if(bHaveProp && pAP)
			{
				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Footnote Property: %s=%s\n", szName, szValue));	
						if(section->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("Footnote Attribute: %s=%s\n", szName, szValue));	
						if(section->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}
			}

			return document->addFootnote(shared_section) == UT_OK;
		}
		case PTX_SectionFrame:
        {
			const gchar* frameType = NULL;

			if(!(bHaveProp && pAP))
				return true;

			if(!(pAP->getProperty("frame-type",frameType) && frameType && *frameType))
				return true;

			if(!strcmp(frameType,"textbox"))
			{
				bInTextbox = true;
			}
			else if(!strcmp(frameType,"image"))
			{
				// TODO: handle positioned images
			}

			if(bInTextbox)
			{
				textbox = new OXML_Element_TextBox(getNextId());
				OXML_SharedElement shared_textbox(static_cast<OXML_Element*>(textbox));

				OXML_Element_Run* element_run = new OXML_Element_Run(getNextId());
				OXML_SharedElement shared_element_run(static_cast<OXML_Element*>(element_run));

				if(element_run->appendElement(shared_textbox) != UT_OK)
					return false;

				const gchar* szValue;
				const gchar* szName;
				size_t propCount = pAP->getPropertyCount();

				size_t i;
				for(i=0; i<propCount; i++)
				{
					if(pAP->getNthProperty(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("TextBox Property: %s=%s\n", szName, szValue));	
						if(textbox->setProperty(szName, szValue) != UT_OK)
							return false;		
					}
				}

				size_t attrCount = pAP->getAttributeCount();

				for(i=0; i<attrCount; i++)
				{
					if(pAP->getNthAttribute(i, szName, szValue))
					{
						//TODO: Take the debug message out when we are done
						UT_DEBUGMSG(("TextBox Attribute: %s=%s\n", szName, szValue));	
						if(textbox->setAttribute(szName, szValue) != UT_OK)
							return false;		
					}
				}

				return paragraph->appendElement(shared_element_run) == UT_OK;
			}
			return true;
		}
		case PTX_EndCell:
		{
			tableHelper.CloseCell();
			if(m_cellStack.empty())
				return false;

			m_cellStack.pop();
			return true;
		}
		case PTX_EndTable:
		{
			tableHelper.CloseTable();
			if(m_tableStack.empty())
				return false;

			//pop the rows that belong to this table
			int nRows = m_tableStack.top()->getNumberOfRows();
			for(int i=0; i<nRows; i++)
			{
				if(m_rowStack.empty())
					return false;
			
				m_rowStack.pop();
			}

			//pop the table
			m_tableStack.pop();
			return true;
		}
		case PTX_EndFootnote:
		{
			section = savedSection; //recover the last section
			paragraph = savedParagraph; //recover the last paragraph
			return true;
		}
		case PTX_EndEndnote:
		{
			section = savedSection; //recover the last section
			paragraph = savedParagraph; //recover the last paragraph
			return true;
		}
		case PTX_EndFrame:
		{
			if(bInTextbox)
				bInTextbox = false;
			return true;
		}
		case PTX_SectionMarginnote:
		case PTX_SectionAnnotation:
		case PTX_SectionTOC:
		case PTX_EndMarginnote:
		case PTX_EndAnnotation:
		case PTX_EndTOC:	
		default:
			return true;
	}

	return true;
}
示例#28
0
void XDBF::injectSettingEntry(Setting_Entry *entry, unsigned long long id)
{
    char *data;
    if (id == 0)
        id = getNextId(ET_SETTING);
    switch (entry->type)
    {
        case SET_INT32:
            injectSettingEntry_private(&entry->i32_data, 4, entry, id);
            break;
        case SET_INT64:
            injectSettingEntry_private(&entry->i64_data, 8, entry, id);
            break;
        case SET_DOUBLE:
            injectSettingEntry_private(&entry->double_data, 8, entry, id);
            break;
        case SET_FLOAT:
            injectSettingEntry_private(&entry->float_data, 4, entry, id);
            break;
        case SET_UNICODE:
        {
            // allocate the perfect amount of memory for the entry
            data = new char[entry->unicode_string.str_len_in_bytes + 24];
            // zero the memory
            memset(data, 0, entry->unicode_string.str_len_in_bytes + 24);
            // write the entry meta data
            writeSettingMetaData(data, id, SET_UNICODE);

            // copy the characters to the array
            for (int i = 0; i < entry->unicode_string.str->length(); i++)
            {
                ((unsigned short*)data)[i + 12] = (unsigned short)entry->unicode_string.str->at(i);
                SwapEndian(&((unsigned short*)data)[i + 12], 1, 2);
            }

            data[entry->unicode_string.str->length()] = 0;

            // write the entry
            injectEntry_private(ET_SETTING, data, entry->unicode_string.str_len_in_bytes + 24, id);

            // give that string back to memory
            delete[] data;
            break;
        }
        case SET_DATETIME:
            // allocate the correct amount of memory for the entry
            data = new char[0x18];
            // zero the memory
            memset(data, 0, 0x18);
            // write the entry meta data
            writeSettingMetaData(data, id, SET_DATETIME);

            // swap the endian for writing
            SwapEndian(&entry->time_stamp.dwHighDateTime);
            SwapEndian(&entry->time_stamp.dwLowDateTime);

            // copy the data time to the write buffer
            memcpy(data + 0x10, &entry->time_stamp, 8);

            // swap the endian back so the value isn't screwed up
            SwapEndian(&entry->time_stamp.dwHighDateTime);
            SwapEndian(&entry->time_stamp.dwLowDateTime);

            // inject the entry
            injectEntry_private(ET_SETTING, data, 0x18, id);
            break;
        case SET_BINARY:
            if(entry->binary.size > 0x3E8)
                throw "Binary data too large to inject. Max = 1000(0x3E8)";

            int size = entry->binary.size + 0x18;
            char *buffer = new char[size];
            memset(buffer, 0, size);
            writeSettingMetaData(buffer, id, SET_BINARY);
            SwapEndian(&entry->binary.size);
            *(int*)&buffer[0x10] = entry->binary.size;
            SwapEndian(&entry->binary.size);
            memcpy(&buffer[0x18], entry->binary.data, entry->binary.size);
            injectEntry_private(ET_SETTING, buffer, size, id);
            break;
    }
}
示例#29
0
void XDBF::injectImageEntry(char *imageData, unsigned int len, unsigned long long id)
{
    injectEntry_private(ET_IMAGE, imageData, len, (id == 0) ? getNextId(ET_IMAGE) : id);
}
示例#30
0
//------------------------------------------------------------------------------
// process() -- 
//------------------------------------------------------------------------------
void Sar::process(const LCreal dt)
{
    BaseClass::process(dt);

    // Imaging in porgress?
   if (timer > 0) {

      // ---
      // Point the beam
      // ---
      Antenna* ant = getAntenna();
      if (ant != 0) {
         
         Simulation* s = getSimulation();
         double refLat = s->getRefLatitude();
         double refLon = s->getRefLongitude();

         osg::Vec3 pos;
         Basic::Nav::convertLL2PosVec(
            refLat, refLon,                           // Ref point (at sea level)
            getStarePointLatitude(), getStarePointLongitude(), getStarePointElevation(), 
            &pos); // x,y,z  NED

         // Platform (ownship) coord and then body
         osg::Vec3 posP = pos - getOwnship()->getPosition();
         osg::Vec3 posB = getOwnship()->getRotMat() * posP;

         // Convert to az/el
         LCreal tgt_az = 0.0;   // Angle (degs)
         LCreal tgt_el = 0.0;   // Angle (degs)
         xyz2AzEl(posB, &tgt_az, &tgt_el);

         // Command to that position
         LCreal az = tgt_az * (LCreal)Basic::Angle::D2RCC;
         LCreal el = tgt_el * (LCreal)Basic::Angle::D2RCC;

         ant->setRefAzimuth(az);
         ant->setRefElevation(el);
         ant->setScanMode(Antenna::CONICAL_SCAN);
      }

      // ---
      // Process timer
      // ---
      LCreal ttimer = timer - dt;
      if (ttimer <= 0) {

         // ### test -- Generate a test image ###
         Image* p = new Image();
         p->testImage(width,height);
         p->setImageId(getNextId());
         p->setLatitude(getStarePointLatitude());
         p->setLongitude(getStarePointLongitude());
         p->setElevation(getStarePointElevation());
         p->setOrientation(0);
         if (isMessageEnabled(MSG_INFO)) {
            std::cout << "Sar:: Generating test image: resolution: " << getResolution() << std::endl;
         }
         if (getResolution() > 0) p->setResolution( getResolution() );
         else p->setResolution( 3.0f * Basic::Distance::FT2M );
         Basic::Pair* pp = new Basic::Pair("image", p);
         addImage(pp);
         // ### TEST TEST 

         // Just finished!
         ttimer = 0;
         setTransmitterEnableFlag(false);
      }
      timer = ttimer;
   }

   BaseClass::updateData(dt);
}