//----------------------------------------------------------------------------// Image& ImageManager::create(const String& type, const String& name) { if (d_images.find(name) != d_images.end()) CEGUI_THROW(AlreadyExistsException( "Image already exists: " + name)); ImageFactoryRegistry::iterator i(d_factories.find(type)); if (i == d_factories.end()) CEGUI_THROW(UnknownObjectException( "Unknown Image type: " + type)); ImageFactory* factory = i->second; Image& image = factory->create(name); d_images[name] = std::make_pair(&image, factory); char addr_buff[32]; sprintf(addr_buff, "%p", static_cast<void*>(&image)); Logger::getSingleton().logEvent( "[ImageManager] Created image: '" + name + "' (" + addr_buff + ") of type: " + type); return image; }
//----------------------------------------------------------------------------// void NamedElement::setName(const String& name) { if (d_name == name) return; if (getParentElement()) { NamedElement* parent = dynamic_cast<NamedElement*>(getParentElement()); if (parent && parent->isChild(name)) { CEGUI_THROW(AlreadyExistsException("Failed to rename " "NamedElement at: " + getNamePath() + " as: " + name + ". A Window " "with that name is already attached as a sibling.")); } } // log this under informative level Logger::getSingleton().logEvent("Renamed element at: " + getNamePath() + " as: " + name, Informative); d_name = name; NamedElementEventArgs args(this); onNameChanged(args); }
/************************************************************************* Create a new window of the specified type *************************************************************************/ Window* WindowManager::createWindow(const String& type, const String& name) { String finalName(name.empty() ? generateUniqueWindowName() : name); if (isWindowPresent(finalName)) { throw AlreadyExistsException("WindowManager::createWindow - A Window object with the name '" + finalName +"' already exists within the system."); } WindowFactoryManager& wfMgr = WindowFactoryManager::getSingleton(); WindowFactory* factory = wfMgr.getFactory(type); Window* newWindow = factory->createWindow(finalName); Logger::getSingleton().logEvent("Window '" + finalName +"' of type '" + type + "' has been created.", Informative); // see if we need to assign a look to this window if (wfMgr.isFalagardMappedType(type)) { // this was a mapped type, so assign a look to the window so it can finalise // its initialisation newWindow->setLookNFeel(type, wfMgr.getMappedLookForType(type)); } // perform initialisation step newWindow->initialise(); d_windowRegistry[finalName] = newWindow; return newWindow; }
/************************************************************************* Adds a WindowFactory object to the registry *************************************************************************/ void WindowFactoryManager::addFactory(WindowFactory* factory) { // throw exception if passed factory is null. if (!factory) { throw NullObjectException( "The provided WindowFactory pointer was invalid."); } // throw exception if type name for factory is already in use if (d_factoryRegistry.find(factory->getTypeName()) != d_factoryRegistry.end()) { throw AlreadyExistsException( "A WindowFactory for type '" + factory->getTypeName() + "' is already registered."); } // add the factory to the registry d_factoryRegistry[factory->getTypeName()] = factory; char addr_buff[32]; sprintf(addr_buff, "(%p)", static_cast<void*>(factory)); Logger::getSingleton().logEvent("WindowFactory for '" + factory->getTypeName() +"' windows added. " + addr_buff); }
// Add function to insert data into the summary text file // // parameter[in]: addVector is a vector of strings for the data to be entered // the first element is product_id // the second element is total_quantity // throw: AlreadyExistsException if product_id already exists // postcondition: Summary is sorted by product_id void Summary::add(vector<string> addVector) throw(AlreadyExistsException) { ifstream infstream; // ifstream to be used to read summary.txt ofstream outfstream; // ofstream to be used to write to summary.txt int delimPos; // int used to store the position of the first delimiter string product_id = addVector[0]; // product_id to be added to file string total_quantity = addVector[1]; // total_quantity to be added to file string currentRow; // string that stores the current row on the summary table string productID; // string to store the product_id in the current row vector<string> fileVector; // vector of strings to be used for storing the text file and sorting // open the summary.txt file infstream.open(fileName); if(infstream.is_open()) { // while loop continues as long as there is another line in the text file // finds the highest product_id in the file and stores it in product_id while(infstream.good()) { getline(infstream, currentRow); // store next line of textfile in currentRow // adds currentRow to the vector if it is not empty // which can occur if there are no more valid entries in the table if(!currentRow.empty()) fileVector.push_back(currentRow); // Searches for the position of the delimiter delimPos = currentRow.find('|'); // stores the current product_id into productID productID = currentRow.substr(0, delimPos); // Throw AlreadyExistsException if product id already exists if(product_id == productID) { throw AlreadyExistsException("product_id already exists"); } } } infstream.close(); fileVector.push_back(product_id + "|" + total_quantity); // adds new row to vector sort(fileVector.begin(), fileVector.end()); // sorts the fileVector // opens and clears summary.txt for output outfstream.open(fileName, ios_base::trunc); // copy fileVector to summary.txt for(int i = 0; i < (int) fileVector.size(); i++) outfstream << fileVector[i] << "\n"; outfstream.close(); }
/************************************************************************* Add a new event to the EventSet *************************************************************************/ void EventSet::addEvent(const String& name) { if (isEventPresent(name)) { throw AlreadyExistsException("An event named '" + name + "' already exists in the EventSet."); } d_events[name] = new Event(name); }
//----------------------------------------------------------------------------// void AnimationManager::addInterpolator(Interpolator* interpolator) { if (d_interpolators.find(interpolator->getType()) != d_interpolators.end()) { CEGUI_THROW(AlreadyExistsException("Interpolator of type '" + interpolator->getType() + "' already exists.")); } d_interpolators.insert( std::make_pair(interpolator->getType(), interpolator)); }
//----------------------------------------------------------------------------// Texture& OpenGL3Renderer::createTexture(const String& name) { if (d_textures.find(name) != d_textures.end()) CEGUI_THROW(AlreadyExistsException( "A texture named '" + name + "' already exists.")); OpenGL3Texture* tex = new OpenGL3Texture(*this, name); d_textures[name] = tex; logTextureCreation(name); return *tex; }
//----------------------------------------------------------------------------// Texture& DirectFBRenderer::createTexture(const CEGUI::String& name) { if (d_textures.find(name) != d_textures.end()) CEGUI_THROW(AlreadyExistsException( "A texture named '" + name + "' already exists.")); DirectFBTexture* tex = new DirectFBTexture(d_directfb, name); d_textures[name] = tex; logTextureCreation(tex); return *tex; }
//----------------------------------------------------------------------------// Texture& OpenGLRendererBase::createTexture(const String& name, const Sizef& size) { if (d_textures.find(name) != d_textures.end()) CEGUI_THROW(AlreadyExistsException( "A texture named '" + name + "' already exists.")); OpenGLTexture* tex = CEGUI_NEW_AO OpenGLTexture(*this, name, size); d_textures[name] = tex; logTextureCreation(name); return *tex; }
Scheme& SchemeManager::doExistingObjectAction( const String object_name, Scheme* object, const XMLResourceExistsAction action) { String event_name; if (isDefined(object_name)) { switch (action) { case XREA_RETURN: Logger::getSingleton().logEvent("---- Returning existing instance " "of " + d_resourceType + " named '" + object_name + "'."); // delete any new object we already had created delete object; // return existing instance of object. return *d_registeredSchemes[object_name]; case XREA_REPLACE: Logger::getSingleton().logEvent("---- Replacing existing instance " "of " + d_resourceType + " named '" + object_name + "' (DANGER!)."); destroy(object_name); event_name = EventResourceReplaced; break; case XREA_THROW: delete object; throw AlreadyExistsException( "an object of type '" + d_resourceType + "' named '" + object_name + "' already exists in the collection."); default: delete object; throw InvalidRequestException( "Invalid CEGUI::XMLResourceExistsAction was specified."); } } else event_name = EventResourceCreated; d_registeredSchemes[object_name] = object; doPostObjectAdditionAction(*object); // fire event about this resource change ResourceEventArgs args(d_resourceType, object_name); fireEvent(event_name, args, EventNamespace); return *object; }
/************************************************************************* Create an empty Imageset that has the given name and uses the given Texture *************************************************************************/ Imageset* ImagesetManager::createImageset(const String& name, Texture* texture) { Logger::getSingleton().logEvent((utf8*)"Attempting to create Imageset '" + name +"' with texture only."); if (isImagesetPresent(name)) { throw AlreadyExistsException("ImagesetManager::createImageset - An Imageset object named '" + name + "' already exists."); } Imageset* temp = new Imageset(name, texture); d_imagesets[name] = temp; return temp; }
//----------------------------------------------------------------------------// void EventSet::addEvent(Event& event) { const String name(event.getName()); if (isEventPresent(name)) { CEGUI_DELETE_AO &event; CEGUI_THROW(AlreadyExistsException( "An event named '" + name + "' already exists in the EventSet.")); } d_events.insert(std::make_pair(name, &event)); }
/************************************************************************* Add a new property to the set *************************************************************************/ void PropertySet::addProperty(Property* property) { if (property == NULL) { throw NullObjectException((utf8*)"The given Property object pointer is NULL."); } if (d_properties.find(property->getName()) != d_properties.end()) { throw AlreadyExistsException((utf8*)"A Property named '" + property->getName() + (utf8*)"' already exists in the PropertySet."); } d_properties[property->getName()] = property; }
/************************************************************************* Create an Imageset object from the specified image file. *************************************************************************/ Imageset* ImagesetManager::createImagesetFromImageFile(const String& name, const String& filename, const String& resourceGroup) { Logger::getSingleton().logEvent((utf8*)"Attempting to create Imageset '" + name + "' using image file '" + filename + "'."); if (isImagesetPresent(name)) { throw AlreadyExistsException("ImagesetManager::createImageset - An Imageset object named '" + name + "' already exists."); } Imageset* temp = new Imageset(name, filename, resourceGroup); d_imagesets[name] = temp; return temp; }
/************************************************************************* Add a new property to the set *************************************************************************/ void PropertySet::addProperty(Property* property) { if (!property) { CEGUI_THROW(NullObjectException("The given Property object pointer is invalid.")); } if (!d_properties.insert(std::make_pair(property->getName(), property)).second) { CEGUI_THROW(AlreadyExistsException("A Property named '" + property->getName() + "' already exists in the PropertySet.")); } property->initialisePropertyReceiver(this); }
//----------------------------------------------------------------------------// Texture& OpenGLRenderer::createTexture(const String& name, GLuint tex, const Sizef& sz) { if (d_textures.find(name) != d_textures.end()) CEGUI_THROW(AlreadyExistsException( "A texture named '" + name + "' already exists.")); OpenGLTexture* t = new OpenGLTexture(*this, name, tex, sz); d_textures[name] = t; logTextureCreation(name); return *t; }
void MapSector::insertBlock(MapBlock *block) { s16 block_y = block->getPos().Y; MapBlock *block2 = getBlockBuffered(block_y); if(block2 != NULL){ throw AlreadyExistsException("Block already exists"); } v2s16 p2d(block->getPos().X, block->getPos().Z); assert(p2d == m_pos); // Insert into container m_blocks.insert(block_y, block); }
/************************************************************************* Add a new WindowRenderer factory *************************************************************************/ void WindowRendererManager::addFactory(WindowRendererFactory* wr) { if (wr == 0) { return; } if (d_wrReg.insert(std::make_pair(wr->getName(), wr)).second == false) { throw AlreadyExistsException("A WindowRendererFactory named '"+wr->getName()+"' already exist"); } String addressStr = SharedStringstream::GetPointerAddressAsString(wr); Logger::getSingleton().logEvent("WindowRendererFactory '"+wr->getName()+ "' added. " + addressStr); }
/************************************************************************* Add a new property to the set *************************************************************************/ void PropertySet::addProperty(Property* property) { if (!property) { CEGUI_THROW(NullObjectException("The given Property object pointer is invalid.")); } if (d_properties.find(property->getName()) != d_properties.end()) { CEGUI_THROW(AlreadyExistsException("A Property named '" + property->getName() + "' already exists in the PropertySet.")); } d_properties[property->getName()] = property; property->initialisePropertyReceiver(this); }
//----------------------------------------------------------------------------// Image& ImageManager::create(const XMLAttributes& attributes) { static const String type_default("BasicImage"); const String& type(attributes.getValueAsString(ImageTypeAttribute, type_default)); const String& name(attributes.getValueAsString(ImageNameAttribute)); if (name.empty()) CEGUI_THROW(InvalidRequestException( "Invalid (empty) image name passed to create.")); if (d_images.find(name) != d_images.end()) CEGUI_THROW(AlreadyExistsException( "Image already exists: " + name)); ImageFactoryRegistry::iterator i(d_factories.find(type)); if (i == d_factories.end()) CEGUI_THROW(UnknownObjectException( "Unknown Image type: " + type)); ImageFactory* factory = i->second; Image& image = factory->create(attributes); // sanity check that the created image uses the name specified in the // attributes block if (image.getName() != name) { const String message( "Factory for type: " + type + " created Image named: " + image.getName() + ". Was expecting name: " + name); factory->destroy(image); CEGUI_THROW(InvalidRequestException(message)); } d_images[name] = std::make_pair(&image, factory); char addr_buff[32]; sprintf(addr_buff, "%p", static_cast<void*>(&image)); Logger::getSingleton().logEvent( "[ImageManager] Created image: '" + name + "' (" + addr_buff + ") of type: " + type); return image; }
/************************************************************************* defines a new Image. *************************************************************************/ void Imageset::defineImage(const String& name, const Rect& image_rect, const Point& render_offset) { if (isImageDefined(name)) { throw AlreadyExistsException("Imageset::defineImage - An image with the name '" + name + "' already exists in Imageset '" + d_name + "'."); } // get scaling factors float hscale = d_autoScale ? d_horzScaling : 1.0f; float vscale = d_autoScale ? d_vertScaling : 1.0f; // add the Image definition d_images[name] = Image(this, name, image_rect, render_offset, hscale, vscale); CEGUI_LOGINSANE("Image '" + name + "' has been defined for Imageset '" + d_name + "'.") }
void SharedFile::createFile() { // create the file first int fd = scidb::File::openFile(getName().c_str(), (O_RDONLY|O_CREAT|O_EXCL)); if (fd < 0) { int err=errno; if (err==EEXIST) { throw AlreadyExistsException(err, REL_FILE, __FUNCTION__, __LINE__); } throw SystemErrorException(err, REL_FILE, __FUNCTION__, __LINE__); } if (scidb::File::closeFd(fd) != 0) { int err=errno; throw SystemErrorException(err, REL_FILE, __FUNCTION__, __LINE__); } }
/************************************************************************* Add a new WindowRenderer factory *************************************************************************/ void WindowRendererManager::addFactory(WindowRendererFactory* wr) { if (wr == 0) { return; } if (d_wrReg.insert(std::make_pair(wr->getName(), wr)).second == false) { CEGUI_THROW(AlreadyExistsException("A WindowRendererFactory named '"+wr->getName()+"' already exist")); } char addr_buff[32]; sprintf(addr_buff, "(%p)", static_cast<void*>(wr)); Logger::getSingleton().logEvent("WindowRendererFactory '"+wr->getName()+ "' added. " + addr_buff); }
//----------------------------------------------------------------------------// void NamedElement::addChild_impl(Element* element) { NamedElement* named_element = dynamic_cast<NamedElement*>(element); if (named_element) { const NamedElement* const existing = getChildByNamePath_impl(named_element->getName()); if (existing && named_element != existing) CEGUI_THROW(AlreadyExistsException("Failed to add " "Element named: " + named_element->getName() + " to element at: " + getNamePath() + " since an Element with that name is already " "attached.")); } Element::addChild_impl(element); }
/************************************************************************* Adds a WindowFactory object to the registry *************************************************************************/ void WindowFactoryManager::addFactory(WindowFactory* factory) { // throw exception if passed factory is null. if (factory == NULL) { throw NullObjectException((utf8*)"WindowFactoryManager::addFactory - The provided WindowFactory pointer was NULL"); } // throw exception if type name for factory is already in use if (d_factoryRegistry.find(factory->getTypeName()) != d_factoryRegistry.end()) { throw AlreadyExistsException((utf8*)"WindowFactoryManager::addFactory - A WindowFactory for type '" + factory->getTypeName() + (utf8*)"' is already registered."); } // add the factory to the registry d_factoryRegistry[factory->getTypeName()] = factory; Logger::getSingleton().logEvent((utf8*)"WindowFactory for '" + factory->getTypeName() +"' windows added."); }
void SharedMemory::create(AccessMode amode) { if (_shm || _region) { throw InvalidStateException(REL_FILE, __FUNCTION__, __LINE__); } try { _shm.reset(new shared_memory_object(create_only, getName().c_str(), static_cast<boost::interprocess::mode_t>(amode))); } catch(boost::interprocess::interprocess_exception &ex) { std::cerr << "shm::create error:" << ex.what() << std::endl; if (ex.get_error_code() == boost::interprocess::already_exists_error) { throw AlreadyExistsException(ex.get_native_error(), REL_FILE, __FUNCTION__, __LINE__); } if (ex.get_error_code() != boost::interprocess::no_error) { throw SystemErrorException(ex.get_native_error(), REL_FILE, __FUNCTION__, __LINE__); } throw; } }
/************************************************************************* Create an Imageset object from the specified file *************************************************************************/ Imageset* ImagesetManager::createImageset(const String& filename, const String& resourceGroup ) { Logger::getSingleton().logEvent((utf8*)"Attempting to create an Imageset from the information specified in file '" + filename + "'."); Imageset* temp = new Imageset(filename, resourceGroup ); String name = temp->getName(); if (isImagesetPresent(name)) { delete temp; throw AlreadyExistsException("ImagesetManager::createImageset - An Imageset object named '" + name + "' already exists."); } d_imagesets[name] = temp; return temp; }
void MapBlockObjectList::add(MapBlockObject *object) throw(ContainerFullException, AlreadyExistsException) { if(object == NULL) { dstream<<"MapBlockObjectList::add(): NULL object"<<std::endl; return; } JMutexAutoLock lock(m_mutex); // Create unique id if id==-1 if(object->m_id == -1) { object->m_id = getFreeId(); } if(m_objects.find(object->m_id) != NULL) { dstream<<"MapBlockObjectList::add(): " "object with same id already exists"<<std::endl; throw AlreadyExistsException ("MapBlockObjectList already has given id"); } object->m_block = m_block; object->setBlockChanged(); /*v3f p = object->m_pos; dstream<<"MapBlockObjectList::add(): " <<"m_block->getPos()=(" <<m_block->getPos().X<<"," <<m_block->getPos().Y<<"," <<m_block->getPos().Z<<")" <<" inserting object with id="<<object->m_id <<" pos=" <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")" <<std::endl;*/ m_objects.insert(object->m_id, object); }
CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier) { if (qualifier.isUninitialized()) throw UninitializedObjectException(); if (find(qualifier.getName()) != PEG_NOT_FOUND) { MessageLoaderParms parms("Common.CIMQualifierList.QUALIFIER", "qualifier \"$0\"", qualifier.getName().getString()); throw AlreadyExistsException(parms); } _qualifiers.append(qualifier); // Update key index: if (_keyIndex == PEGASUS_ORDEREDSET_INDEX_UNKNOWN && qualifier._rep->_name == _KEY) _keyIndex = _qualifiers.size()-1; return *this; }