示例#1
0
文件: tree.cpp 项目: Ashatta/study
bool Tree::hasString(char * key, TreeNode * node)
{
    if (node == NULL)
        return false;
    if (strcmp(key, node->key) == 0)
        return true;
    else if (strcmp(key, node->key) < 0)
        return hasString(key, node->leftChild);
    else
        return hasString(key, node->rightChild);
}
BOOL LLPanelGroupExperiences::postBuild()
{
	mExperiencesList = getChild<LLFlatListView>("experiences_list");
	if (hasString("loading_experiences"))
	{
		mExperiencesList->setNoItemsCommentText(getString("loading_experiences"));
	}
	else if (hasString("no_experiences"))
	{
		mExperiencesList->setNoItemsCommentText(getString("no_experiences"));
	}

	return LLPanelGroupTab::postBuild();
}
示例#3
0
文件: Parameter.cpp 项目: xth1/lwr
string Parameter::getString(string key)
{
    if (!hasString(key)) {
        cout<<key + "is not a valid string parameter"<<endl;
        throw key + "is not a valid string parameter";
    }
    return this->string_map[key];
}
 bool ConfigurationManager::configure(std::string name, std::string& variable, std::string defaultValue) {
     if(!hasString(name)) {
         setString(name, defaultValue);
         variable = defaultValue;
         return false;
     }
     variable = getString(name);
     return true;
 }
示例#5
0
const Common::UString &LocString::getString() const {
	uint32 languageID = LangMan.getLanguageID(LangMan.getCurrentLanguageText(), LangMan.getCurrentGender());

	// Look whether we have an internal localized string
	if (hasString(languageID))
		return getString(languageID);

	// Try the differently gendered internal string
	if (hasString(LangMan.swapLanguageGender(languageID)))
		return getString(LangMan.swapLanguageGender(languageID));

	// Next, try the external localized one
	const Common::UString &refString = getStrRefString();
	if (!refString.empty())
		return refString;

	// If all else fails, just get the first one available
	return getFirstString();
}
    std::string ConfigurationManager::getString(std::string name)
    {
        if (hasString(name)) {
            return stringMap[name];
        } else {
	    printf("did not find variable %s \n",name.c_str());
            LOG("Settings Error", "Variable not found, use the \"hasString\" function first");
            return "";
        }
    }
示例#7
0
std::string AbstractDynamicEntry::printToStdOut() const
{
    std::stringstream returnValue;
    returnValue << "\ttag=" << createTag(m_tag) << ", value=";
    if (hasString())
    {
        returnValue << m_stringValue;
    }
    else
    {
        returnValue << "0x" << std::hex << m_value;
    }
    returnValue << "\n";

    return returnValue.str();
}
void LLPreview::refreshFromItem()
{
	const LLInventoryItem* item = getItem();
	if (!item)
	{
		return;
	}
	if (hasString("Title"))
	{
		LLStringUtil::format_map_t args;
		args["[NAME]"] = item->getName();
		LLUIString title = getString("Title", args);
		setTitle(title.getString());
	}
	getChild<LLUICtrl>("desc")->setValue(item->getDescription());

	getChildView("desc")->setEnabled(canModify(mObjectUUID, item));
}
void LLPanelGroupExperiences::setExperienceList(const LLSD& experiences)
{
	if (hasString("no_experiences"))
	{
		mExperiencesList->setNoItemsCommentText(getString("no_experiences"));
	}
    mExperiencesList->clear();

    LLSD::array_const_iterator it = experiences.beginArray();
    for ( /**/ ; it != experiences.endArray(); ++it)
    {
        LLUUID public_key = it->asUUID();
        LLExperienceItem* item = new LLExperienceItem();

        item->init(public_key);
        mExperiencesList->addItem(item, public_key);
    }
}
示例#10
0
void LLPreview::refreshFromItem()
{
	const LLInventoryItem* item = getItem();
	if (!item)
	{
		return;
	}
	if (hasString("Title"))
	{
		LLStringUtil::format_map_t args;
		args["[NAME]"] = item->getName();
		LLUIString title = getString("Title", args);
		setTitle(title.getString());
	}
	getChild<LLUICtrl>("desc")->setValue(item->getDescription());

	BOOL can_agent_manipulate = item->getPermissions().allowModifyBy(gAgent.getID());
	getChildView("desc")->setEnabled(can_agent_manipulate);
}
示例#11
0
bool LocString::hasString(Language language, LanguageGender gender) const {
	if (gender == kLanguageGenderCurrent)
		gender = LangMan.getCurrentGender();

	return hasString(LangMan.getLanguageID(language, gender));
}
示例#12
0
bool LocString::hasString(Language language, LanguageGender gender) const {
	return hasString(LangMan.getLanguageID(language, gender));
}
示例#13
0
/** \brief Print command on serial console */
void GCode::printCommand()
{
    if(hasM())
    {
        Com::print('M');
        Com::print((int)M);
        Com::print(' ');
    }
    if(hasG())
    {
        Com::print('G');
        Com::print((int)G);
        Com::print(' ');
    }
    if(hasT())
    {
        Com::print('T');
        Com::print((int)T);
        Com::print(' ');
    }
    if(hasX())
    {
        Com::printF(Com::tX,X);
    }
    if(hasY())
    {
        Com::printF(Com::tY,Y);
    }
    if(hasZ())
    {
        Com::printF(Com::tZ,Z);
    }
    if(hasE())
    {
        Com::printF(Com::tE,E,4);
    }
    if(hasF())
    {
        Com::printF(Com::tF,F);
    }
    if(hasS())
    {
        Com::printF(Com::tS,S);
    }
    if(hasP())
    {
        Com::printF(Com::tP,P);
    }
    if(hasI())
    {
        Com::printF(Com::tI,I);
    }
    if(hasJ())
    {
        Com::printF(Com::tJ,J);
    }
    if(hasR())
    {
        Com::printF(Com::tR,R);
    }
    if(hasString())
    {
        Com::print(text);
    }
    Com::println();
}
示例#14
0
/**
  Converts a ascii GCode line into a GCode structure.
*/
bool GCode::parseAscii(char *line,bool fromSerial)
{
    bool has_checksum = false;
    char *pos;
    params = 0;
    params2 = 0;
    if((pos = strchr(line,'N'))!=0)   // Line number detected
    {
        actLineNumber = parseLongValue(++pos);
        params |=1;
        N = actLineNumber & 0xffff;
    }
    if((pos = strchr(line,'M'))!=0)   // M command
    {
        M = parseLongValue(++pos) & 0xffff;
        params |= 2;
        if(M>255) params |= 4096;
    }
    if(hasM() && (M == 23 || M == 28 || M == 29 || M == 30 || M == 32 || M == 117))
    {
        // after M command we got a filename for sd card management
        char *sp = line;
        while(*sp!='M') sp++; // Search M command
        while(*sp!=' ') sp++; // search next whitespace
        while(*sp==' ') sp++; // skip leading whitespaces
        text = sp;
        while(*sp)
        {
            if((M != 117 && *sp==' ') || *sp=='*') break; // end of filename reached
            sp++;
        }
        *sp = 0; // Removes checksum, but we don't care. Could also be part of the string.
        waitUntilAllCommandsAreParsed = true; // don't risk string be deleted
        params |= 32768;
    }
    else
    {
        if((pos = strchr(line,'G'))!=0)   // G command
        {
            G = parseLongValue(++pos) & 0xffff;
            params |= 4;
            if(G>255) params |= 4096;
        }
        if((pos = strchr(line,'X'))!=0)
        {
            X = parseFloatValue(++pos);
            params |= 8;
        }
        if((pos = strchr(line,'Y'))!=0)
        {
            Y = parseFloatValue(++pos);
            params |= 16;
        }
        if((pos = strchr(line,'Z'))!=0)
        {
            Z = parseFloatValue(++pos);
            params |= 32;
        }
        if((pos = strchr(line,'E'))!=0)
        {
            E = parseFloatValue(++pos);
            params |= 64;
        }
        if((pos = strchr(line,'F'))!=0)
        {
            F = parseFloatValue(++pos);
            params |= 256;
        }
        if((pos = strchr(line,'T'))!=0)   // M command
        {
            T = parseLongValue(++pos) & 0xff;
            params |= 512;
        }
        if((pos = strchr(line,'S'))!=0)   // M command
        {
            S = parseLongValue(++pos);
            params |= 1024;
        }
        if((pos = strchr(line,'P'))!=0)   // M command
        {
            P = parseLongValue(++pos);
            params |= 2048;
        }
        if((pos = strchr(line,'I'))!=0)
        {
            I = parseFloatValue(++pos);
            params2 |= 1;
            params |= 4096; // Needs V2 for saving
        }
        if((pos = strchr(line,'J'))!=0)
        {
            J = parseFloatValue(++pos);
            params2 |= 2;
            params |= 4096; // Needs V2 for saving
        }
        if((pos = strchr(line,'R'))!=0)
        {
            R = parseFloatValue(++pos);
            params2 |= 4;
            params |= 4096; // Needs V2 for saving
        }
    }
    if((pos = strchr(line,'*'))!=0)   // checksum
    {
        uint8_t checksum_given = parseLongValue(pos+1);
        uint8_t checksum = 0;
        while(line!=pos) checksum ^= *line++;
#if FEATURE_CHECKSUM_FORCED
        Printer::flag0 |= PRINTER_FLAG0_FORCE_CHECKSUM;
#endif
        if(checksum!=checksum_given)
        {
            if(Printer::debugErrors())
            {
                Com::printErrorFLN(Com::tWrongChecksum);
            }
            return false; // mismatch
        }
    }
#if FEATURE_CHECKSUM_FORCED
    else
    {
        if(!fromSerial) return true;
        if(hasM() && (M == 110 || hasString())) return true;
        if(Printer::debugErrors())
        {
            Com::printErrorFLN(Com::tMissingChecksum);
        }
        return false;
    }
#endif
    if(hasFormatError() || (params & 518)==0)   // Must contain G, M or T command and parameter need to have variables!
    {
        formatErrors++;
        if(Printer::debugErrors())
            Com::printErrorFLN(Com::tFormatError);
        if(formatErrors<3) return false;
    }
    else formatErrors = 0;
    return true;
}
示例#15
0
/**
  Converts a binary uint8_tfield containing one GCode line into a GCode structure.
  Returns true if checksum was correct.
*/
bool GCode::parseBinary(uint8_t *buffer,bool fromSerial)
{
    unsigned int sum1=0,sum2=0; // for fletcher-16 checksum
    // first do fletcher-16 checksum tests see
    // http://en.wikipedia.org/wiki/Fletcher's_checksum
    uint8_t *p = buffer;
    uint8_t len = binaryCommandSize-2;
    while (len)
    {
        uint8_t tlen = len > 21 ? 21 : len;
        len -= tlen;
        do
        {
            sum1 += *p++;
            if(sum1>=255) sum1-=255;
            sum2 += sum1;
            if(sum2>=255) sum2-=255;
        }
        while (--tlen);
    }
    sum1 -= *p++;
    sum2 -= *p;
    if(sum1 | sum2)
    {
        if(Printer::debugErrors())
        {
            Com::printErrorFLN(Com::tWrongChecksum);
        }
        return false;
    }
    p = buffer;
    params = *(unsigned int *)p;
    p+=2;
    uint8_t textlen=16;
    if(isV2())
    {
        params2 = *(unsigned int *)p;
        p+=2;
        if(hasString())
            textlen = *p++;
    }
    else params2 = 0;
    if(params & 1)
    {
        actLineNumber=N=*(uint16_t *)p;
        p+=2;
    }
    if(isV2())   // Read G,M as 16 bit value
    {
        if(params & 2)
        {
            M=*(uint16_t *)p;
            p+=2;
        }
        if(params & 4)
        {
            G=*(uint16_t *)p;
            p+=2;
        }
    }
    else
    {
        if(params & 2)
        {
            M=*p++;
        }
        if(params & 4)
        {
            G=*p++;
        }
    }
    //if(code->params & 8) {memcpy(&code->X,p,4);p+=4;}
    if(params & 8)
    {
        X=*(float *)p;
        p+=4;
    }
    if(params & 16)
    {
        Y=*(float *)p;
        p+=4;
    }
    if(params & 32)
    {
        Z =*(float *)p;
        p+=4;
    }
    if(params & 64)
    {
        E=*(float *)p;
        p+=4;
    }
    if(params & 256)
    {
        F=*(float *)p;
        p+=4;
    }
    if(params & 512)
    {
        T=*p++;
    }
    if(params & 1024)
    {
        S=*(int32_t*)p;
        p+=4;
    }
    if(params & 2048)
    {
        P=*(int32_t*)p;
        p+=4;
    }
    if(hasI())
    {
        I=*(float *)p;
        p+=4;
    }
    if(hasJ())
    {
        J=*(float *)p;
        p+=4;
    }
    if(hasR())
    {
        R=*(float *)p;
        p+=4;
    }
    if(hasString())   // set text pointer to string
    {
        text = (char*)p;
        text[textlen] = 0; // Terminate string overwriting checksum
        waitUntilAllCommandsAreParsed=true; // Don't destroy string until executed
    }
    formatErrors = 0;
    return true;
}