本文整理汇总了C++中std::string::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ string::empty方法的具体用法?C++ string::empty怎么用?C++ string::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MAX
bool
TeSQLite::generateLabelPositions(TeTheme *theme, const std::string& objectId)
{
string geomTable, upd;
string collTable = theme->collectionTable();
if((collTable.empty()) || (!tableExist(collTable)))
return false;
if( theme->layer()->hasGeometry(TeCELLS) )
{
geomTable = theme->layer()->tableName(TeCELLS);
upd= "UPDATE " + collTable + " SET ";
upd += " label_x = (SELECT MAX(lower_x + (upper_x - lower_x)/2) ";
upd += "FROM " + geomTable + " WHERE object_id = c_object_id), ";
upd += " label_y = (SELECT MAX(lower_y + (upper_y - lower_y)/2) ";
upd += "FROM " + geomTable + " WHERE object_id = c_object_id) ";
upd += " WHERE label_x IS NULL OR label_y IS NULL";
}
if( theme->layer()->hasGeometry(TePOLYGONS) )
{
geomTable = theme->layer()->tableName(TePOLYGONS);
upd= "UPDATE " + collTable + " SET ";
upd += " label_x = (SELECT MAX(lower_x + (upper_x - lower_x)/2) ";
upd += "FROM " + geomTable + " WHERE object_id = c_object_id), ";
upd += " label_y = (SELECT MAX(lower_y + (upper_y - lower_y)/2) ";
upd += "FROM " + geomTable + " WHERE object_id = c_object_id) ";
upd += " WHERE label_x IS NULL OR label_y IS NULL";
}
if( theme->layer()->hasGeometry(TeLINES) )
{
geomTable = theme->layer()->tableName(TeLINES);
upd= "UPDATE " + collTable + " SET ";
upd += " label_x = (SELECT MAX(lower_x + (upper_x - lower_x)/2) ";
upd += "FROM " + geomTable + " WHERE object_id = c_object_id), ";
upd += " label_y = (SELECT MAX(lower_y + (upper_y - lower_y)/2) ";
upd += "FROM " + geomTable + " WHERE object_id = c_object_id) ";
upd += " WHERE label_x IS NULL OR label_y IS NULL";
}
if(theme->layer()->hasGeometry(TePOINTS))
{
geomTable = theme->layer()->tableName(TePOINTS);
upd= " UPDATE " + collTable + " SET ";
upd += " label_x = (SELECT MAX(x) ";
upd += " FROM " + geomTable + " p WHERE object_id = c_object_id), ";
upd += " label_y = (SELECT MAX(y) ";
upd += " FROM " + geomTable + " p WHERE object_id = c_object_id) ";
upd += " WHERE label_x IS NULL OR label_y IS NULL";
}
if (!upd.empty())
{
if (!objectId.empty())
{
upd += " AND c_object_id='"+objectId+"'";
}
if(!execute(upd))
return false;
}
return true;
}
示例2: ParseDouble
bool ParseDouble(const std::string& string, double& value)
{
return swri_string_util::ToDouble(string, value) || string.empty();
}
示例3:
bool ParseUInt32(const std::string& string, uint32_t& value, int32_t base)
{
return swri_string_util::ToUInt32(string, value, base) || string.empty();
}
示例4: parseLine
bool Parser::parseLine(std::string &ErrStr) {
switch (CurTok.K) {
case Token::Ident:
if (CurTok.str() == "cand") {
if (RK == ReplacementKind::ParseLHS) {
ErrStr = makeErrStr("Not expecting 'cand' when parsing LHS");
return false;
}
if (RK == ReplacementKind::ParseRHS) {
ErrStr = makeErrStr("Not expecting 'cand' when parsing RHS");
return false;
}
if (!consumeToken(ErrStr)) return false;
InstMapping Cand = parseInstMapping(ErrStr);
if (!ErrStr.empty()) return false;
Reps.push_back(ParsedReplacement{Cand, std::move(PCs),
std::move(BPCs)});
nextReplacement();
return true;
} else if (CurTok.str() == "infer") {
if (RK == ReplacementKind::ParseRHS) {
ErrStr = makeErrStr("Not expecting 'infer' when parsing RHS");
return false;
}
if (!consumeToken(ErrStr)) return false;
if (LHS) {
ErrStr = makeErrStr("Not expecting a second 'infer'");
return false;
}
LHS = parseInst(ErrStr);
if (!LHS)
return false;
if (RK == ReplacementKind::ParseLHS) {
Reps.push_back(ParsedReplacement{InstMapping(LHS, 0),
std::move(PCs), std::move(BPCs)});
nextReplacement();
}
return true;
} else if (CurTok.str() == "result") {
if (RK == ReplacementKind::ParseLHS) {
ErrStr = makeErrStr("Not expecting 'result' when parsing LHS");
return false;
}
if (RK != ReplacementKind::ParseRHS && !LHS) {
ErrStr = makeErrStr("Not expecting 'result' before 'infer'");
return false;
}
if (!consumeToken(ErrStr)) return false;
Inst *RHS = parseInst(ErrStr);
if (!RHS)
return false;
InstMapping Cand = InstMapping(LHS, RHS);
Reps.push_back(ParsedReplacement{Cand, std::move(PCs),
std::move(BPCs)});
nextReplacement();
return true;
} else if (CurTok.str() == "pc") {
if (!consumeToken(ErrStr)) return false;
InstMapping PC = parseInstMapping(ErrStr);
if (!ErrStr.empty()) return false;
PCs.push_back(PC);
return true;
} else if (CurTok.str() == "blockpc") {
if (!consumeToken(ErrStr)) return false;
if (CurTok.K != Token::ValName) {
ErrStr = makeErrStr("expected block var");
return false;
}
StringRef InstName = CurTok.Name;
unsigned InstWidth = CurTok.Width;
if (InstWidth != 0) {
ErrStr = makeErrStr("blocks may not have a width");
return false;
}
if (Context.getInst(CurTok.Name)) {
ErrStr = makeErrStr(std::string("%") + InstName.str() +
" is declared as an inst");
return false;
}
Block *B = Context.getBlock(InstName);
if (B == 0) {
ErrStr = makeErrStr(std::string("block %") + InstName.str() +
" is undeclared");
return false;
}
if (!consumeToken(ErrStr)) return false;
if (CurTok.K != Token::UntypedInt) {
ErrStr = makeErrStr(std::string("expected block number"));
return false;
}
unsigned CurrIdx = CurTok.Val.getLimitedValue();
//.........这里部分代码省略.........
示例5: main
void file_server::main(std::string file_name)
{
std::string path;
if(!check_in_document_root(file_name,path)) {
show404();
return;
}
int s=file_mode(path);
if((s & S_IFDIR)) {
std::string path2;
int mode_2=0;
bool have_index = check_in_document_root(file_name+"/" + index_file_ ,path2);
if(have_index) {
mode_2 = file_mode(path2);
have_index = (mode_2 & S_IFREG) != 0;
}
if( !file_name.empty()
&& file_name[file_name.size()-1]!='/' // not ending with "/" as should
&& (have_index || list_directories_)
)
{
response().set_redirect_header(file_name + "/");
response().out()<<std::flush;
return;
}
if(have_index) {
path = path2;
s=mode_2;
}
else {
if(list_directories_)
list_dir(file_name,path);
else
show404();
return;
}
}
if(!(s & S_IFREG)) {
show404();
return;
}
std::string ext;
size_t pos = path.rfind('.');
if(pos != std::string::npos)
ext=path.substr(pos);
mime_type::const_iterator p=mime_.find(ext);
if(p!=mime_.end())
response().content_type(p->second);
else
response().content_type("application/octet-stream");
if(!allow_deflate_) {
response().io_mode(http::response::nogzip);
}
booster::nowide::ifstream file(path.c_str(),std::ios_base::binary);
if(!file) {
show404();
return;
}
response().out()<<file.rdbuf(); // write stream to stream
}
示例6: hasLookupURL
bool hasLookupURL()
{
return !sLookupURL.empty();
}
示例7: addCustomFunctionSource
void addCustomFunctionSource(const std::string& filename, const std::string& source) {
CPPADCG_ASSERT_KNOWN(!filename.empty(), "The filename name cannot be empty");
_customSource[filename] = source;
}
示例8: setError
void FUGNetzteil::setError(std::string command, std::string error)
{
if (error=="E0") return;
lastError ="";
lastError += boost::posix_time::to_iso_extended_string(boost::posix_time::second_clock::local_time());
lastError +=" ";
lastError += command;
lastError += " ; ";
error.erase( std::remove(error.begin(), error.end(), '\n'), error.end() );
lastError += error;
lastError += ": ";
std::string discription;
int errorNum;
error.erase( std::remove(error.begin(), error.end(), 'E'), error.end() );
if(!error.empty())
errorNum = std::stoi (error);
else
errorNum = -1;
if (errorNum == 1)
{
discription="keine Daten verfügbar";
}
else if (errorNum == 2)
{
discription="unbekannter Register-Typ";
}
else if (errorNum == 4)
{
discription="ungültiges Argument";
}
else if (errorNum == 5)
{
discription="Bereich überschritten";
}
else if (errorNum == 6)
{
discription="Register darf nur gelesen werden";
}
else if (errorNum == 7)
{
discription="Receive Overflow";
}
else if (errorNum ==8 )
{
discription="EEPROM ist schreibgeschützt";
}
else if (errorNum == 9)
{
discription="Adressfehler";
}
else if (errorNum ==10 )
{
discription="unbekannter SCPI Befehl";
}
else if (errorNum ==11 )
{
discription="Trigger on Talk Fehler";
}
else if (errorNum ==12 )
{
discription="~Tn Befehl hatte ungültiges Argument";
}
else if (errorNum ==13 )
{
discription="ungültiger N-Wert";
}
else if (errorNum == 14)
{
discription="Register darf nurbeschrieben werden";
}
else if (errorNum == 15)
{
discription="String zu lang";
}
else if (errorNum == 101||errorNum == 102||errorNum == 103)
{
discription="Checksumme falsch";
}
else
{
discription="unbekannter Fehler";
}
lastError += discription;
return;
}
示例9: msg
void
XMLSocket_as::checkForIncomingData()
{
assert(ready());
std::vector<std::string> msgs;
const int bufSize = 10000;
boost::scoped_array<char> buf(new char[bufSize]);
const size_t bytesRead = _socket.readNonBlocking(buf.get(), bufSize - 1);
// Return if there's no data.
if (!bytesRead) return;
if (buf[bytesRead - 1] != 0) {
// We received a partial message, so bung
// a null-terminator on the end.
buf[bytesRead] = 0;
}
char* ptr = buf.get();
while (static_cast<size_t>(ptr - buf.get()) < bytesRead) {
#ifdef GNASH_XMLSOCKET_DEBUG
log_debug ("read: %d, this string ends: %d", bytesRead,
ptr + std::strlen(ptr) - buf.get());
#endif
std::string msg(ptr);
// If the string reaches to the final byte read, it's
// incomplete. Store it and continue. The buffer is
// NULL-terminated, so this cannot read past the end.
if (static_cast<size_t>(
ptr + std::strlen(ptr) - buf.get()) == bytesRead) {
_remainder += msg;
break;
}
if (!_remainder.empty()) {
msgs.push_back(_remainder + msg);
ptr += msg.size() + 1;
_remainder.clear();
continue;
}
// Don't do anything if nothing is received.
msgs.push_back(msg);
ptr += msg.size() + 1;
}
if (msgs.empty()) return;
#ifdef GNASH_XMLSOCKET_DEBUG
for (size_t i = 0, e = msgs.size(); i != e; ++i) {
log_debug(_(" Message %d: %s "), i, msgs[i]);
}
#endif
for (XMLSocket_as::MessageList::const_iterator it=msgs.begin(),
itEnd=msgs.end(); it != itEnd; ++it) {
callMethod(&owner(), NSV::PROP_ON_DATA, *it);
}
if (_socket.bad()) {
callMethod(&owner(), NSV::PROP_ON_CLOSE);
close();
return;
}
}
示例10: parse
SmartPtrCLogicalRelationshipDoc LogicalRelationshipXml::parse(
const SmartPtrCXmlElement thisXml) {
CAF_CM_STATIC_FUNC_VALIDATE("LogicalRelationshipXml", "parse");
SmartPtrCLogicalRelationshipDoc logicalRelationshipDoc;
CAF_CM_ENTER {
CAF_CM_VALIDATE_SMARTPTR(thisXml);
const std::string namespaceValStrVal =
thisXml->findRequiredAttribute("namespace");
const std::string namespaceValVal = namespaceValStrVal;
const std::string nameStrVal =
thisXml->findRequiredAttribute("name");
const std::string nameVal = nameStrVal;
const std::string versionStrVal =
thisXml->findRequiredAttribute("version");
const std::string versionVal = versionStrVal;
const std::string arityStrVal =
thisXml->findRequiredAttribute("arity");
ARITY_TYPE arityVal = ARITY_NONE;
if (! arityStrVal.empty()) {
arityVal = EnumConvertersXml::convertStringToArityType(arityStrVal);
}
const SmartPtrCXmlElement dataClassLeftXml =
thisXml->findRequiredChild("dataClassLeft");
SmartPtrCClassCardinalityDoc dataClassLeftVal;
if (! dataClassLeftXml.IsNull()) {
dataClassLeftVal = ClassCardinalityXml::parse(dataClassLeftXml);
}
const SmartPtrCXmlElement dataClassRightXml =
thisXml->findRequiredChild("dataClassRight");
SmartPtrCClassCardinalityDoc dataClassRightVal;
if (! dataClassRightXml.IsNull()) {
dataClassRightVal = ClassCardinalityXml::parse(dataClassRightXml);
}
const CXmlElement::SmartPtrCElementCollection joinChildrenXml =
thisXml->findRequiredChildren("join");
std::deque<SmartPtrCJoinTypeDoc> joinVal;
if (! joinChildrenXml.IsNull() && ! joinChildrenXml->empty()) {
for (TConstIterator<CXmlElement::CElementCollection> joinXmlIter(*joinChildrenXml);
joinXmlIter; joinXmlIter++) {
const SmartPtrCXmlElement joinXml = joinXmlIter->second;
const SmartPtrCJoinTypeDoc joinDoc =
JoinTypeXml::parse(joinXml);
joinVal.push_back(joinDoc);
}
}
const std::string descriptionStrVal =
thisXml->findOptionalAttribute("description");
const std::string descriptionVal = descriptionStrVal;
logicalRelationshipDoc.CreateInstance();
logicalRelationshipDoc->initialize(
namespaceValVal,
nameVal,
versionVal,
arityVal,
dataClassLeftVal,
dataClassRightVal,
joinVal,
descriptionVal);
}
CAF_CM_EXIT;
return logicalRelationshipDoc;
}
示例11: lmTransactionStart
/* ****************************************************************************
*
* httpRequestSendWithCurl -
*
* The waitForResponse arguments specifies if the method has to wait for response
* before return. If this argument is false, the return string is ""
*
* NOTE
* We are using a hybrid approach, consisting in a static thread-local buffer of a
* small size that copes with most notifications to avoid expensive
* calloc/free syscalls if the notification payload is not very large.
*
* RETURN VALUES
* httpRequestSendWithCurl returns 0 on success and a negative number on failure:
* -1: Invalid port
* -2: Invalid IP
* -3: Invalid verb
* -4: Invalid resource
* -5: No Content-Type BUT content present
* -6: Content-Type present but there is no content
* -7: Total outgoing message size is too big
* -9: Error making HTTP request
*/
int httpRequestSendWithCurl
(
CURL *curl,
const std::string& _ip,
unsigned short port,
const std::string& protocol,
const std::string& verb,
const std::string& tenant,
const std::string& servicePath,
const std::string& xauthToken,
const std::string& resource,
const std::string& orig_content_type,
const std::string& content,
bool useRush,
bool waitForResponse,
std::string* outP,
const std::string& acceptFormat,
long timeoutInMilliseconds
)
{
char portAsString[STRING_SIZE_FOR_INT];
static unsigned long long callNo = 0;
std::string result;
std::string ip = _ip;
struct curl_slist* headers = NULL;
MemoryStruct* httpResponse = NULL;
CURLcode res;
int outgoingMsgSize = 0;
std::string content_type(orig_content_type);
++callNo;
// For content-type application/json we add charset=utf-8
if (orig_content_type == "application/json")
{
content_type += "; charset=utf-8";
}
if (timeoutInMilliseconds == -1)
{
timeoutInMilliseconds = defaultTimeout;
}
lmTransactionStart("to", ip.c_str(), port, resource.c_str());
// Preconditions check
if (port == 0)
{
LM_E(("Runtime Error (port is ZERO)"));
lmTransactionEnd();
*outP = "error";
return -1;
}
if (ip.empty())
{
LM_E(("Runtime Error (ip is empty)"));
lmTransactionEnd();
*outP = "error";
return -2;
}
if (verb.empty())
{
LM_E(("Runtime Error (verb is empty)"));
lmTransactionEnd();
*outP = "error";
return -3;
}
if (resource.empty())
{
LM_E(("Runtime Error (resource is empty)"));
lmTransactionEnd();
//.........这里部分代码省略.........
示例12: add
void LogicalRelationshipXml::add(
const SmartPtrCLogicalRelationshipDoc logicalRelationshipDoc,
const SmartPtrCXmlElement thisXml) {
CAF_CM_STATIC_FUNC_VALIDATE("LogicalRelationshipXml", "add");
CAF_CM_ENTER {
CAF_CM_VALIDATE_SMARTPTR(logicalRelationshipDoc);
CAF_CM_VALIDATE_SMARTPTR(thisXml);
const std::string namespaceValVal = logicalRelationshipDoc->getNamespaceVal();
CAF_CM_VALIDATE_STRING(namespaceValVal);
thisXml->addAttribute("namespace", namespaceValVal);
const std::string nameVal = logicalRelationshipDoc->getName();
CAF_CM_VALIDATE_STRING(nameVal);
thisXml->addAttribute("name", nameVal);
const std::string versionVal = logicalRelationshipDoc->getVersion();
CAF_CM_VALIDATE_STRING(versionVal);
thisXml->addAttribute("version", versionVal);
const std::string arityVal =
EnumConvertersXml::convertArityTypeToString(logicalRelationshipDoc->getArity());
CAF_CM_VALIDATE_STRING(arityVal);
thisXml->addAttribute("arity", arityVal);
const SmartPtrCClassCardinalityDoc dataClassLeftVal =
logicalRelationshipDoc->getDataClassLeft();
CAF_CM_VALIDATE_SMARTPTR(dataClassLeftVal);
const SmartPtrCXmlElement dataClassLeftXml =
thisXml->createAndAddElement("dataClassLeft");
ClassCardinalityXml::add(dataClassLeftVal, dataClassLeftXml);
const SmartPtrCClassCardinalityDoc dataClassRightVal =
logicalRelationshipDoc->getDataClassRight();
CAF_CM_VALIDATE_SMARTPTR(dataClassRightVal);
const SmartPtrCXmlElement dataClassRightXml =
thisXml->createAndAddElement("dataClassRight");
ClassCardinalityXml::add(dataClassRightVal, dataClassRightXml);
const std::deque<SmartPtrCJoinTypeDoc> joinVal =
logicalRelationshipDoc->getJoinCollection();
CAF_CM_VALIDATE_STL(joinVal);
if (! joinVal.empty()) {
for (TConstIterator<std::deque<SmartPtrCJoinTypeDoc> > joinIter(joinVal);
joinIter; joinIter++) {
const SmartPtrCXmlElement joinXml =
thisXml->createAndAddElement("join");
JoinTypeXml::add(*joinIter, joinXml);
}
}
const std::string descriptionVal = logicalRelationshipDoc->getDescription();
if (! descriptionVal.empty()) {
thisXml->addAttribute("description", descriptionVal);
}
}
CAF_CM_EXIT;
}
示例13: table_info
static bool table_info(std::string & key_field,
bool detected_types,
std::string & field,
std::string & table,
mapnik::layer_descriptor & desc,
boost::shared_ptr<sqlite_connection> ds)
{
// http://www.sqlite.org/pragma.html#pragma_table_info
// use pragma table_info to detect primary key
// and to detect types if no subquery is used or
// if the subquery-based type detection failed
std::ostringstream s;
s << "PRAGMA table_info(" << table << ")";
boost::shared_ptr<sqlite_resultset> rs(ds->execute_query(s.str()));
bool found_table = false;
bool found_pk = false;
while (rs->is_valid() && rs->step_next())
{
found_table = true;
const char* fld_name = rs->column_text(1);
std::string fld_type(rs->column_text(2));
int fld_pk = rs->column_integer(5);
boost::algorithm::to_lower(fld_type);
// TODO - how to handle primary keys on multiple columns ?
if (key_field.empty() && ! found_pk && fld_pk != 0)
{
key_field = fld_name;
found_pk = true;
}
if (! detected_types)
{
// see 2.1 "Column Affinity" at http://www.sqlite.org/datatype3.html
// TODO - refactor this somehow ?
if (field.empty()
&& ((boost::algorithm::contains(fld_type, "geom") ||
boost::algorithm::contains(fld_type, "point") ||
boost::algorithm::contains(fld_type, "linestring") ||
boost::algorithm::contains(fld_type, "polygon"))
||
(boost::algorithm::icontains(fld_name, "geom") ||
boost::algorithm::icontains(fld_name, "point") ||
boost::algorithm::icontains(fld_name, "linestring") ||
boost::algorithm::icontains(fld_name, "polygon")))
)
{
field = std::string(fld_name);
}
else if (boost::algorithm::contains(fld_type, "int"))
{
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Integer));
}
else if (boost::algorithm::contains(fld_type, "text") ||
boost::algorithm::contains(fld_type, "char") ||
boost::algorithm::contains(fld_type, "clob"))
{
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String));
}
else if (boost::algorithm::contains(fld_type, "real") ||
boost::algorithm::contains(fld_type, "float") ||
boost::algorithm::contains(fld_type, "double"))
{
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Double));
}
else if (boost::algorithm::contains(fld_type, "blob"))
{
if (! field.empty())
{
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String));
}
}
#ifdef MAPNIK_DEBUG
else
{
// "Column Affinity" says default to "Numeric" but for now we pass..
//desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
// TODO - this should not fail when we specify geometry_field in XML file
std::clog << "Sqlite Plugin: column '"
<< std::string(fld_name)
<< "' unhandled due to unknown type: "
<< fld_type << std::endl;
}
#endif
}
}
return found_table;
}
示例14: GetDirectory
bool CGUIWindowAddonBrowser::GetDirectory(const std::string& strDirectory, CFileItemList& items)
{
bool result;
if (URIUtils::PathEquals(strDirectory, "addons://downloading/"))
{
VECADDONS addons;
CAddonInstaller::GetInstance().GetInstallList(addons);
CURL url(strDirectory);
CAddonsDirectory::GenerateAddonListing(url, addons, items, g_localizeStrings.Get(24067));
result = true;
items.SetPath(strDirectory);
if (m_guiState.get() && !m_guiState->HideParentDirItems())
{
CFileItemPtr pItem(new CFileItem(".."));
pItem->SetPath(m_history.GetParentPath());
pItem->m_bIsFolder = true;
pItem->m_bIsShareOrDrive = false;
items.AddFront(pItem, 0);
}
}
else
{
result = CGUIMediaWindow::GetDirectory(strDirectory, items);
if (result && CAddonsDirectory::IsRepoDirectory(CURL(strDirectory)))
{
if (CSettings::GetInstance().GetBool(CSettings::SETTING_GENERAL_ADDONFOREIGNFILTER))
{
int i = 0;
while (i < items.Size())
{
auto prop = items[i]->GetProperty("Addon.Language");
if (!prop.isNull() && IsForeign(prop.asString()))
items.Remove(i);
else
++i;
}
}
if (CSettings::GetInstance().GetBool(CSettings::SETTING_GENERAL_ADDONBROKENFILTER))
{
for (int i = items.Size() - 1; i >= 0; i--)
{
if (!items[i]->GetProperty("Addon.Broken").empty())
{
//check if it's installed
AddonPtr addon;
if (!CAddonMgr::GetInstance().GetAddon(items[i]->GetProperty("Addon.ID").asString(), addon))
items.Remove(i);
}
}
}
}
}
if (strDirectory.empty() && CAddonInstaller::GetInstance().IsDownloading())
{
CFileItemPtr item(new CFileItem("addons://downloading/", true));
item->SetLabel(g_localizeStrings.Get(24067));
item->SetLabelPreformated(true);
item->SetIconImage("DefaultNetwork.png");
items.Add(item);
}
items.SetContent("addons");
for (int i = 0; i < items.Size(); ++i)
SetItemLabel2(items[i]);
return result;
}
示例15: create_listener
int create_listener (
listener*& new_listener,
unsigned short port,
const std::string& ip
)
{
// ensure that WSAStartup has been called and WSACleanup will eventually
// be called when program ends
sockets_startup();
sockaddr_in sa; // local socket structure
ZeroMemory(&sa,sizeof(sockaddr_in)); // initialize sa
SOCKET sock = socket (AF_INET, SOCK_STREAM, 0); // get a new socket
// if socket() returned an error then return OTHER_ERROR
if (sock == INVALID_SOCKET )
{
return OTHER_ERROR;
}
// set the local socket structure
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
if (ip.empty())
{
// if the listener should listen on any IP
sa.sin_addr.S_un.S_addr = htons(INADDR_ANY);
}
else
{
// if there is a specific ip to listen on
sa.sin_addr.S_un.S_addr = inet_addr(ip.c_str());
// if inet_addr cound't convert the ip then return an error
if ( sa.sin_addr.S_un.S_addr == INADDR_NONE )
{
closesocket(sock);
return OTHER_ERROR;
}
}
// set the SO_REUSEADDR option
int flag_value = 1;
setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,reinterpret_cast<const char*>(&flag_value),sizeof(int));
// bind the new socket to the requested port and ip
if (bind(sock,reinterpret_cast<sockaddr*>(&sa),sizeof(sockaddr_in))==SOCKET_ERROR)
{ // if there was an error
closesocket(sock);
// if the port is already bound then return PORTINUSE
if (WSAGetLastError() == WSAEADDRINUSE)
return PORTINUSE;
else
return OTHER_ERROR;
}
// tell the new socket to listen
if ( listen(sock,SOMAXCONN) == SOCKET_ERROR)
{
// if there was an error return OTHER_ERROR
closesocket(sock);
// if the port is already bound then return PORTINUSE
if (WSAGetLastError() == WSAEADDRINUSE)
return PORTINUSE;
else
return OTHER_ERROR;
}
// determine the port used if necessary
if (port == 0)
{
sockaddr_in local_info;
int length = sizeof(sockaddr_in);
if ( getsockname (
sock,
reinterpret_cast<sockaddr*>(&local_info),
&length
) == SOCKET_ERROR
)
{
closesocket(sock);
return OTHER_ERROR;
}
port = ntohs(local_info.sin_port);
}
// initialize a listener object on the heap with the new socket
try { new_listener = new listener(sock,port,ip); }
catch(...) { closesocket(sock); return OTHER_ERROR; }
return 0;
}