bool Platform::satisfy_platform(Platform* os)
{
    bool ret = (!strlen(os->getName()))? true : (compareString(getName(), os->getName()));
    ret &= (!strlen(os->getDistribution()))? true : (compareString(strDistrib.c_str(), os->getDistribution()));
    ret &= (!strlen(os->getRelease()))? true : (compareString(strRelease.c_str(), os->getRelease()));
    return ret;
}
Beispiel #2
0
bool Texture::load(FS::IFile& file)
{
	PROFILE_FUNCTION();

	const char* path = getPath().c_str();
	size_t len = getPath().length();
	bool loaded = false;
	if (len > 3 && compareString(path + len - 4, ".dds") == 0)
	{
		loaded = loadDDS(file);
	}
	else if (len > 3 && compareString(path + len - 4, ".raw") == 0)
	{
		loaded = loadRaw(file);
	}
	else
	{
		loaded = loadTGA(file);
	}
	if (!loaded)
	{
		g_log_warning.log("Renderer") << "Error loading texture " << path;
		return false;
	}

	m_size = file.size();
	return true;
}
 void recursive(string temp, vector<char> &nums1, vector<char> &nums2, string &low, string &high, int &total) {
     int len = temp.length();
     if (len > low.length() && len < high.length()) {
         if (len > 1 && temp[0] != '0') total++;
     }
     else if (len == low.length() && len < high.length()) {
         if (compareString(low, temp)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     else if (len == high.length() && len > low.length()) {
         if (compareString(temp, high)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     else if (len > high.length()) {
         return;
     }
     else if (len == low.length() && len == high.length()) {
         if (compareString(temp, high) && compareString(low, temp)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     for (int i = 0; i < nums1.size(); ++i) {
         recursive(nums1[i] + temp + nums2[i], nums1, nums2, low, high, total);
     }
 }
void LuaScript::parseProperties()
{
	static const char* PROPERTY_MARK = "-- LUMIX PROPERTY";
	const int PROPERTY_MARK_LENGTH = stringLength(PROPERTY_MARK);
	const char* str = m_source_code.c_str();
	const char* prop = findSubstring(str, PROPERTY_MARK);
	while (prop)
	{
		const char* token = prop + PROPERTY_MARK_LENGTH + 1;

		Property& property = m_properties.pushEmpty();
		token = getToken(token, property.name, sizeof(property.name));
		char type[50];
		token = getToken(token, type, sizeof(type));
		if (compareString(type, "entity") == 0)
		{
			property.type = Property::ENTITY;
		}
		else if (compareString(type, "float") == 0)
		{
			property.type = Property::FLOAT;
		}
		else
		{
			property.type = Property::ANY;
		}

		prop = findSubstring(prop + 1, PROPERTY_MARK);
	}
}
Beispiel #5
0
void Texture::save()
{
	char ext[5];
	ext[0] = 0;
	PathUtils::getExtension(ext, 5, getPath().c_str());
	if (compareString(ext, "raw") == 0 && m_BPP == 2)
	{
		FS::FileSystem& fs = m_resource_manager.getFileSystem();
		FS::IFile* file = fs.open(fs.getDefaultDevice(),
								  getPath(),
								  FS::Mode::CREATE_AND_WRITE);

		file->write(&m_data[0], m_data.size() * sizeof(m_data[0]));
		fs.close(*file);
	}
	else if (compareString(ext, "tga") == 0 && m_BPP == 4)
	{
		saveTGA();
	}
	else
	{
		g_log_error.log("Renderer") << "Texture " << getPath().c_str()
									<< " can not be saved - unsupported format";
	}
}
Beispiel #6
0
void Material::deserializeUniforms(JsonSerializer& serializer)
{
	serializer.deserializeArrayBegin();
	clearUniforms();
	while (!serializer.isArrayEnd())
	{
		Uniform& uniform = m_uniforms.pushEmpty();
		serializer.nextArrayItem();
		serializer.deserializeObjectBegin();
		char label[256];
		auto uniform_type = bgfx::UniformType::End;
		while (!serializer.isObjectEnd())
		{
			serializer.deserializeLabel(label, 255);
			if (compareString(label, "name") == 0)
			{
				serializer.deserialize(uniform.m_name, Uniform::MAX_NAME_LENGTH, "");
				uniform.m_name_hash = crc32(uniform.m_name);
			}
			else if (compareString(label, "int_value") == 0)
			{
				uniform_type = bgfx::UniformType::Int1;
				uniform.m_type = Uniform::INT;
				serializer.deserialize(uniform.m_int, 0);
			}
			else if (compareString(label, "float_value") == 0)
			{
				uniform.m_type = Uniform::FLOAT;
				serializer.deserialize(uniform.m_float, 0);
			}
			else if (compareString(label, "matrix_value") == 0)
			{
				uniform_type = bgfx::UniformType::Mat4;
				uniform.m_type = Uniform::MATRIX;
				serializer.deserializeArrayBegin();
				for (int i = 0; i < 16; ++i)
				{
					serializer.deserializeArrayItem(uniform.m_matrix[i], 0);
					ASSERT(i == 15 || !serializer.isArrayEnd());
				}
				serializer.deserializeArrayEnd();
			}
			else if (compareString(label, "time") == 0)
			{
				uniform.m_type = Uniform::TIME;
				serializer.deserialize(uniform.m_float, 0);
			}
			else
			{
				g_log_warning.log("material") << "Unknown label \"" << label << "\"";
			}
		}
		uniform.m_handle = bgfx::createUniform(uniform.m_name, uniform_type);

		serializer.deserializeObjectEnd();
	}
	serializer.deserializeArrayEnd();
}
Beispiel #7
0
void InternalPortModel::updateInputPortColor(void)
{
    if((type == INPUTD) && input && (string(input->getName()) != "*"))
    {
        strColor = COLOR_NOMAL;
        if(!destinationArrows.size())
            strColor = (input->isRequired()) ? COLOR_WARNING : COLOR_NOMAL;
        else
        {
            std::vector<ArrowModel*>::iterator itr;
            for(itr=destinationArrows.begin(); itr<destinationArrows.end(); itr++)
                if((*itr)->getSource() && 
                   Glib::RefPtr<InternalPortModel>::cast_dynamic((*itr)->getSource()))
                {
                    OutputData* outp = Glib::RefPtr<InternalPortModel>::cast_dynamic((*itr)->getSource())->getOutput();
                    if(outp && !compareString(outp->getName(), input->getName()))
                    {
                        strColor = COLOR_MISMATCH;
                        break;
                    }
                }
        }
        poly->property_fill_color().set_value(strColor.c_str());
    }    
}
// -----------------------------------------------------------------------------
// Implements checking if a given MIME type is supported or not
// -----------------------------------------------------------------------------
//
TBool CAknsWallpaperPlugin::IsMimeTypeSupportedL(const TDesC& aMimeTypeString)
    {
    // Check for a type separator in the string
    TInt pos = aMimeTypeString.Find(KAknsWallpaperPluginSeparator);

    // Leave if no separator was found.. the MIME
    // standard requires it
    if (pos == KErrNotFound)
        {
        User::Leave(KErrArgument);
        }

    // Copy the full Mime type string (needed for uppercase)
    HBufC* fullBuf = aMimeTypeString.AllocLC();
    TPtr fullString = fullBuf->Des();
    fullString.UpperCase();

    // Construct the compare string
    TPtrC compareString(aMimeTypeString.Left(pos));

    // Perform the comparison
    TBool ret = EFalse;

    // Mime type case:  IMAGE/* except IMAGE/X-OTA-BITMAP
    if (compareString.CompareF(KAknsWallpaperPluginMimeTypeImage) == 0 &&
        !(fullString.CompareF(KAknsWallpaperPluginMimeTypeOTABitmap) == 0))
        {
        ret = ETrue;
        }
    CleanupStack::PopAndDestroy(fullBuf);

    return ret;
    }
Beispiel #9
0
SDB_API int sdb_match (const char *str, const char *glob) {
	int flags = SDB_LIKE_NONE;
	int glob_len;
	int begin = 0;
	if (!str || !glob)
		return 0;
	glob_len = strlen (glob);
	if (haveSuffix (glob, glob_len, "?i")) {
		glob_len -= 2;
		flags |= SDB_LIKE_ICASE;
	}
	if (havePrefix (glob, glob_len, "%")) {
		glob++;
		glob_len--;
		flags |= SDB_LIKE_BASE64;
	}
	if (havePrefix (glob, glob_len, "^")) {
		glob++;
		glob_len--;
		flags |= SDB_LIKE_START;
	}
	if (haveSuffix (glob+begin, glob_len-begin, "$")) {
		glob_len--;
		flags |= SDB_LIKE_END;
	}
	return compareString (str, glob, glob_len, flags);
}
Beispiel #10
0
static void alpha_blending(lua_State* L, const char* mode)
{
	Shader* shader = getShader(L);
	if (!shader) return;
	if (compareString(mode, "add") == 0)
	{
		shader->m_render_states |= BGFX_STATE_BLEND_ADD;
	}
	else if (compareString(mode, "alpha") == 0)
	{
		shader->m_render_states |= BGFX_STATE_BLEND_ALPHA;
	}
	else
	{
		g_log_error.log("Renderer") << "Uknown blend mode " << mode << " in " << shader->getPath().c_str();
	}
}
Beispiel #11
0
bool Model::parseVertexDef(FS::IFile& file, bgfx::VertexDecl* vertex_definition)
{
	vertex_definition->begin();

	uint32 attribute_count;
	file.read(&attribute_count, sizeof(attribute_count));

	for (uint32 i = 0; i < attribute_count; ++i)
	{
		char tmp[50];
		uint32 len;
		file.read(&len, sizeof(len));
		if (len > sizeof(tmp) - 1)
		{
			return false;
		}
		file.read(tmp, len);
		tmp[len] = '\0';

		if (compareString(tmp, "in_position") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
		}
		else if (compareString(tmp, "in_colors") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true, false);
		}
		else if (compareString(tmp, "in_tex_coords") == 0)
		{
			vertex_definition->add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
		}
		else if (compareString(tmp, "in_normal") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (compareString(tmp, "in_tangents") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (compareString(tmp, "in_weights") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Weight, 4, bgfx::AttribType::Float);
		}
		else if (compareString(tmp, "in_indices") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Int16, false, true);
		}
		else
		{
			ASSERT(false);
			return false;
		}

		uint32 type;
		file.read(&type, sizeof(type));
	}

	vertex_definition->end();
	return true;
}
Beispiel #12
0
	IFileDevice* getDevice(const char* device)
	{
		for (int i = 0; i < m_devices.size(); ++i)
		{
			if (compareString(m_devices[i]->name(), device) == 0) return m_devices[i];
		}

		return nullptr;
	}
Beispiel #13
0
		IPlugin* getPlugin(const char* name) override
		{
			for (int i = 0; i < m_plugins.size(); ++i)
			{
				if (compareString(m_plugins[i]->getName(), name) == 0)
				{
					return m_plugins[i];
				}
			}
			return 0;
		}
Beispiel #14
0
RSTATE Executable::state(void)
{

    if(!broker->initialized())
        initialize();

    // Updating real module state on demand
    // Notice that this is a blocking method
    execMachine->refresh();

    const char* strState = execMachine->currentState()->getName();

    if(compareString(strState, "SUSPENDED"))
        return SUSPENDED;
    if(compareString(strState, "READY"))
        return READY;
    if(compareString(strState, "CONNECTING"))
        return CONNECTING;
    if(compareString(strState, "RUNNING"))
        return RUNNING;
    if(compareString(strState, "DEAD"))
        return DEAD;
    if(compareString(strState, "DYING"))
        return DYING;

    std::cerr<<"Unknown state!"<<endl;
    return STUNKNOWN;
}
Beispiel #15
0
	IPlugin* StaticPluginRegister::create(const char* name, Engine& engine)
	{
		auto* i = s_first_plugin;
		while (i)
		{
			if (compareString(name, i->name) == 0)
			{
				return i->creator(engine);
			}
			i = i->next;
		}
		return nullptr;
	}
int insertHashTable(HashTable* hashtable,char* key,int value){
    unsigned int index = hashCode(key)%HASHSIZE;
    hashNode* newNode = (hashNode*)malloc(sizeof(hashNode));
    newNode->key = (char*)malloc(sizeof(char) * (strlen(key)+1));
    memcpy(newNode->key,key,strlen(key)+1);
    newNode->key[strlen(key)]='\0';
    newNode->value = value;
    hashNode* n=searchHashTable(hashtable, key);
    if (n){
        n->value = value;
        return 0;
    }
    else{
        newNode->next = hashtable->content[index];
        hashtable->content[index] = newNode;
        hashtable->size=hashtable->size+1;
        nodeIndex* insertIndex=(nodeIndex*)malloc(sizeof(nodeIndex));
        insertIndex->whichNode=newNode;
        insertIndex->next=NULL;
        nodeIndex* p=hashtable->indexHead;
        if(!p) hashtable->indexHead=insertIndex;
        else if(compareString(p->whichNode->key, key)==1){
            hashtable->indexHead=insertIndex;
            insertIndex->next=p;
        }
        else{
            while (p) {
                if(!p->next||(compareString(p->whichNode->key, key)==-1&&compareString(p->next->whichNode->key, key)==1)){
                    nodeIndex* mid = p->next;
                    p->next=insertIndex;
                    insertIndex->next=mid;
                    break;
                }
                p=p->next;
            }
        }
        return 1;
    }
}
Beispiel #17
0
	int getPassIdx(const char* pass) override
	{
		for (int i = 0; i < m_passes.size(); ++i)
		{
			if (compareString(m_passes[i], pass) == 0)
			{
				return i;
			}
		}

		auto& new_pass = m_passes.pushEmpty();
		copyString(new_pass, pass);
		return m_passes.size() - 1;
	}
Beispiel #18
0
	int getShaderDefineIdx(const char* define) override
	{
		for (int i = 0; i < m_shader_defines.size(); ++i)
		{
			if (compareString(m_shader_defines[i], define) == 0)
			{
				return i;
			}
		}

		auto& new_define = m_shader_defines.pushEmpty();
		copyString(new_define, define);
		return m_shader_defines.size() - 1;
	}
Beispiel #19
0
int main()
{
	char str1[15];
	char str2[15];
	
	printf("Enter first string!");
	scanf("%s", &str1);
	printf("Enter second string");
	scanf("%s", &str2);
	
	compareString(str1, str2);
	findEmbeddedString(str1, str2);
		
	return(0);
	}
Beispiel #20
0
	bool mount(IFileDevice* device) override
	{
		for (int i = 0; i < m_devices.size(); i++)
		{
			if (m_devices[i] == device)
			{
				return false;
			}
		}

		if (compareString(device->name(), "memory") == 0)
		{
			m_memory_device.m_devices[0] = device;
			m_memory_device.m_devices[1] = nullptr;
		}
		else if (compareString(device->name(), "disk") == 0)
		{
			m_disk_device.m_devices[0] = device;
			m_disk_device.m_devices[1] = nullptr;
		}

		m_devices.push(device);
		return true;
	}
Beispiel #21
0
Texture* Material::getTextureByUniform(const char* uniform) const
{
	if (!m_shader)
	{
		return nullptr;
	}

	for (int i = 0, c = m_shader->getTextureSlotCount(); i < c; ++i)
	{
		if (compareString(m_shader->getTextureSlot(i).m_uniform, uniform) == 0)
		{
			return m_textures[i];
		}
	}
	return nullptr;
}
Beispiel #22
0
void InternalPortModel::updateOutputPortColor(void)
{
    if(type == OUTPUTD)
    {
        strColor = COLOR_NOMAL;
        std::vector<ArrowModel*>::iterator itr;
        for(itr=sourceArrows.begin(); itr<sourceArrows.end(); itr++)
            if((*itr)->getDestination() && 
                Glib::RefPtr<InternalPortModel>::cast_dynamic((*itr)->getDestination()))
            {
                InputData* inp = Glib::RefPtr<InternalPortModel>::cast_dynamic((*itr)->getDestination())->getInput();
                if(inp && (string(inp->getName()) != "*") &&
                   !compareString(output->getName(), inp->getName()))
                {
                    strColor = COLOR_MISMATCH;
                    break;
                }
            }
        poly->property_fill_color().set_value(strColor.c_str());
    }    
}
Beispiel #23
0
int main()
{
    myString *fat, *son;
    char in;
    int result = 0;

    initString( &fat );
    initString( &son );

    printf("请输入父串(以#号结束):");

    scanf("%c", &in);
    while( '#'!=in && fat->lenght < MAXSIZE)
    {
        fat->data[fat->lenght++] = in;
        scanf("%c", &in);
    }

    printf("请输入子串(以#号结束):");

    scanf("%c", &in);
    scanf("%c", &in);
    while( '#'!=in && son->lenght < MAXSIZE )
    {
        son->data[son->lenght++] = in;
        scanf("%c", &in);
    }

    result = compareString( *fat, *son );

    if( result )
        printf("父串包含子串。");
    else
        printf("不包含。");


    return 0;
}
Beispiel #24
0
static void uniform(lua_State* L, const char* name, const char* type)
{
	auto* shader = getShader(L);
	if (!shader) return;
	auto& u = shader->m_uniforms.emplace();
	copyString(u.name, name);
	u.name_hash = crc32(name);
	if (compareString(type, "float") == 0)
	{
		u.type = Shader::Uniform::FLOAT;
		u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
	}
	else if (compareString(type, "color") == 0)
	{
		u.type = Shader::Uniform::COLOR;
		u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
	}
	else if (compareString(type, "int") == 0)
	{
		u.type = Shader::Uniform::INT;
		u.handle = bgfx::createUniform(name, bgfx::UniformType::Int1);
	}
	else if (compareString(type, "matrix4") == 0)
	{
		u.type = Shader::Uniform::MATRIX4;
		u.handle = bgfx::createUniform(name, bgfx::UniformType::Mat4);
	}
	else if (compareString(type, "time") == 0)
	{
		u.type = Shader::Uniform::TIME;
		u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
	}
	else if (compareString(type, "vec3") == 0)
	{
		u.type = Shader::Uniform::VEC3;
		u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
	}
	else 
	{
		g_log_error.log("Renderer") << "Unknown uniform type " << type << " in " << shader->getPath().c_str();
	}
}
Beispiel #25
0
 bool operator() (const std::string& a, const std::string& b) const
 {
   return compareString(a.c_str(), b.c_str()) < 0;
 }
Beispiel #26
0
    bool ParserTable::loadFromData(const char* data, size_t size)
    {
        if (compareString(data, size, PARSER_TABLE)) data += strlen(PARSER_TABLE);
        //uchar version = *data;
        ++data;
        data += 8; // timestamp align to 8 bytes
        size_t vtCount = *reinterpret_cast<const size_t*>(data);
        data += sizeof(size_t);
        size_t vnCount = *reinterpret_cast<const size_t*>(data);
        data += sizeof(size_t);
        size_t rulesCount = *reinterpret_cast<const size_t*>(data);
        data += sizeof(size_t);
        size_t itemCount = *reinterpret_cast<const size_t*>(data);
        data += sizeof(size_t);
        iStart = *reinterpret_cast<const uint*>(data);
        data += sizeof(uint);

        vts.reserve(vtCount);
        vns.reserve(vnCount);
        rules.reserve(rulesCount);
        items.reserve(itemCount);
        table.reserve(itemCount * (vtCount + 1 + vnCount));

        for (size_t i = 0; i < itemCount * (vtCount + 1 + vnCount); ++i)
        {
            pair<uchar, ushort> p;
            p.first = *data;
            ++data;
            p.second = *reinterpret_cast<const ushort*>(data);
            data += sizeof(ushort);
            table.push_back(p);
        }

        for (size_t i = 0; i < vtCount; ++i)
        {
            Production::Item item(&ruleContext);
            item.loadFromData(data);
            vts.push_back(item);
        }

        for (size_t i = 0; i < vnCount; ++i)
        {
            Production::Item item;
            item.loadFromData(data);
            vns.push_back(item);
        }

        for (size_t i = 0; i < rulesCount; ++i)
        {
            Production p;
            p.loadFromData(data, &ruleContext);
            rules.push_back(p);
        }

        for (size_t i = 0; i < itemCount; ++i)
        {
            items.push_back(*reinterpret_cast<const uint*>(data));
            data += sizeof(uint);
        }
        return true;
    }
Beispiel #27
0
void chladniRC::onSerialBuffer(const ofx::IO::SerialBufferEventArgs& args){
	
	// Buffers will show up here when the marker character is found.
	string message(args.getBuffer().toString());
	//serialMessages.push_back(message);
	
	// get pingback
	string compareString("pingback:");
	if(message.length()>=compareString.length() ){
		if( message.compare(0,compareString.length(),compareString,0,compareString.length())==0){
			arduinoLastPingReturn = message.substr(compareString.length()-1,message.npos);
			return;
		}
	}
	
	//
	compareString = "EVStatus:";
	if(message.length()>=compareString.length() ){
		if( message.compare(0,compareString.length(),compareString,0,compareString.length())==0){
			
			string rawValue = message.substr(compareString.length(),message.npos);
			
			auto dash = rawValue.find("-");
			if(dash != rawValue.npos){
				int valveID = ofToInt( rawValue.substr(0,dash) );
				
				if( valveID>=0 && valveID<KM_CHLADNI_NUM_ELECTROVALVES){
				
					int valveValue = ofToInt( rawValue.substr(dash+1,rawValue.npos-(dash+1) ) );
					waterControlSettings.waterFlowRate[valveID] = ((float)valveValue)/255.f;
				}
				
			}
			return;
		}
	}
	
	// get the manual LED strip value
	compareString = "ledStripIntensityManu:";
	if(message.length()>=compareString.length() ){
		if( message.compare(0,compareString.length(),compareString,0,compareString.length())==0){
			
			string rawValue = message.substr(compareString.length(),message.npos);
			
			auto dash = rawValue.find("-");
			if(dash != rawValue.npos){
				int lightID = ofToInt( rawValue.substr(0,dash) );
				
				if( lightID>=0 && lightID<KM_CHLADNI_NUM_LED_STRIPS){
					
					int lightValue = ofToInt( rawValue.substr(dash+1,rawValue.npos-(dash+1) ) );
					waterControlSettings.LEDStripsIntensityManu[lightID] = ((float)lightValue)/255.f;
				}
				
			}
			return;
		}
	}
	
	// still not returned? --> unrecognised message
	cout << "Unrecognised chladni SERIAL message:\t" << message << endl;
}
Beispiel #28
0
static unsigned int handleAlpha(ruleset *tree, char *sid, char *mid, char *state, alpha *alphaNode, jsonProperty *allProperties, 
                                void **rulesBinding, unsigned short actionType, unsigned short *commandCount) {
    alpha *alphaStack[MAX_STACK_SIZE];
    jsonProperty *propertyStack[MAX_STACK_SIZE];
    alphaStack[0] = alphaNode;    
    propertyStack[0] = NULL;
    alpha *currentAlpha;
    jsonProperty *currentProperty;
    unsigned short top = 1;
    unsigned int result = ERR_EVENT_NOT_HANDLED;
    unsigned int propertyHash = 1;

    while (top > 0) {       
        --top;
        currentAlpha = alphaStack[top];
        currentProperty = propertyStack[top];
        unsigned char alphaOp = currentAlpha->operator;
        unsigned char propertyMatch = 1;
        if (alphaOp != OP_NEX && alphaOp != OP_EX && alphaOp != OP_TYPE)
        {
            char *propertyLast = currentProperty->lastValue;
            char *propertyFirst = currentProperty->firstValue;
            unsigned char propertyType = currentProperty->type;
            char temp;
            if (!currentProperty->isMaterial) {
                switch(propertyType) {
                    case JSON_INT:
                        ++propertyLast;
                        temp = propertyLast[0];
                        propertyLast[0] = '\0';
                        currentProperty->value.i = atol(propertyFirst);
                        propertyLast[0] = temp;
                        break;
                    case JSON_DOUBLE:
                        ++propertyLast;
                        temp = propertyLast[0];
                        propertyLast[0] = '\0';
                        currentProperty->value.i = atof(propertyFirst);
                        propertyLast[0] = temp;
                        break;
                    case JSON_BOOL:
                        ++propertyLast;
                        unsigned int leftLength = propertyLast - propertyFirst;
                        unsigned char b = 1;
                        if (leftLength == 5 && strncmp("false", propertyFirst, 5)) {
                            b = 0;
                        }
                        currentProperty->value.b = b;
                        break;
                }

                currentProperty->isMaterial = 1;
            }
            
            unsigned short type = propertyType << 8;
            type = type + currentAlpha->right.type;
            int leftLength;
            switch(type) {
                case COMP_BOOL_BOOL:
                    propertyMatch = compareBool(currentProperty->value.b, currentAlpha->right.value.b, alphaOp);
                    break;
                case COMP_BOOL_INT: 
                    propertyMatch = compareInt(currentProperty->value.b, currentAlpha->right.value.i, alphaOp);
                    break;
                case COMP_BOOL_DOUBLE: 
                    propertyMatch = compareDouble(currentProperty->value.b, currentAlpha->right.value.d, alphaOp);
                    break;
                case COMP_BOOL_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
                case COMP_INT_BOOL:
                    propertyMatch = compareInt(currentProperty->value.i, currentAlpha->right.value.b, alphaOp);
                    break;
                case COMP_INT_INT: 
                    propertyMatch = compareInt(currentProperty->value.i, currentAlpha->right.value.i, alphaOp);
                    break;
                case COMP_INT_DOUBLE: 
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.d, alphaOp);
                    break;
                case COMP_INT_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
                case COMP_DOUBLE_BOOL:
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.b, alphaOp);
                    break;
                case COMP_DOUBLE_INT: 
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.i, alphaOp);
                    break;
                case COMP_DOUBLE_DOUBLE: 
                    propertyMatch = compareDouble(currentProperty->value.i, currentAlpha->right.value.d, alphaOp);
                    break;
                case COMP_DOUBLE_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
                case COMP_STRING_BOOL:
                    if (currentAlpha->right.value.b) {
                        propertyMatch = compareString(propertyFirst, propertyLast, "true", alphaOp);
                    }
                    else {
                        propertyMatch = compareString(propertyFirst, propertyLast, "false", alphaOp);
                    }
                    break;
                case COMP_STRING_INT: 
                    {
                        leftLength = propertyLast - propertyFirst + 1;
                        char rightStringInt[leftLength];
                        snprintf(rightStringInt, leftLength, "%ld", currentAlpha->right.value.i);
                        propertyMatch = compareString(propertyFirst, propertyLast, rightStringInt, alphaOp);
                    }
                    break;
                case COMP_STRING_DOUBLE: 
                    {
                        leftLength = propertyLast - propertyFirst + 1;
                        char rightStringDouble[leftLength];
                        snprintf(rightStringDouble, leftLength, "%f", currentAlpha->right.value.d);
                        propertyMatch = compareString(propertyFirst, propertyLast, rightStringDouble, alphaOp);
                        break;
                    }
                case COMP_STRING_STRING:
                    propertyMatch = compareString(propertyFirst, propertyLast, 
                                    &tree->stringPool[currentAlpha->right.value.stringOffset], alphaOp);
                    break;
            }
        }

        if (propertyMatch) {
            unsigned int nextLength = currentAlpha->nextLength;
            unsigned int nextOffset = currentAlpha->nextOffset;   
            for (unsigned int i = 0; i < nextLength; ++i) {
                node *currentNode = &tree->nodePool[tree->nextPool[nextOffset + i]];
                unsigned int nodeHash;
                if (currentNode->type != NODE_ALPHA) {
                    result = handleBeta(tree, sid, mid, state, currentNode, rulesBinding, actionType, commandCount);
                }
                else {
                    nodeHash = currentNode->value.a.hash;
                    propertyHash = 1;
                    for (int ii = 0; propertyHash && (propertyHash != nodeHash) && (ii < MAX_CONFLICTS); ++ii) {
                        currentProperty = &allProperties[(nodeHash & HASH_MASK) + (ii * MAX_BUCKET_LENGTH)];
                        propertyHash = currentProperty->hash;
                    }
                    if (((nodeHash == propertyHash) && (currentNode->value.a.operator != OP_NEX)) || 
                        ((nodeHash != propertyHash) && (currentNode->value.a.operator == OP_NEX))) {
                        if (top == MAX_STACK_SIZE) {
                            return ERR_MAX_STACK_SIZE;
                        }

                        alphaStack[top] =  &currentNode->value.a;
                        propertyStack[top] = currentProperty;
                        ++top;
                    }
                }
            }
        }
    }

    return result;
}
void ApplicationModel::updateChildItems(void)
{

    ModulePContainer modules = parentWindow->manager.getKnowledgeBase()->getModules(application);    
    CnnContainer connections = parentWindow->manager.getKnowledgeBase()->getConnections(application);
    ApplicaitonPContainer applications = parentWindow->manager.getKnowledgeBase()->getApplications(application);

    int index = 0; //index = (index/900)*100+50;
    CnnIterator citr;
    for(citr=connections.begin(); citr<connections.end(); citr++) 
    {
        Connection baseCon = *citr;
        GraphicModel model = baseCon.getModelBase();
        InputData* input = NULL;
        OutputData* output = NULL;
        Glib::RefPtr<PortModel> source(NULL);
        Glib::RefPtr<PortModel> dest(NULL);
        findInputOutputData((*citr), modules, input, output);    
        if(output)
            source = findModelFromOutput(output);
        else
        {
            Glib::RefPtr<ExternalPortModel> extPort;
            bool bExist = false;
            for(int i=0; i<get_n_children(); i++)
            {
                extPort = Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i));
                if(extPort && compareString(extPort->getPort(), baseCon.from()))
                {
                    source = extPort;
                    bExist = true;
                    break;
                }    
            }
            if(!bExist)
            {
                source = ExternalPortModel::create(parentWindow, OUTPUTD, (*citr).from(), true);
                add_child(source);
                 double x ,y;
                if(model.points.size() > 1)
                {
                    x = model.points[1].x - Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getWidth()
                                              - bounds.get_x1()+ITEMS_MARGIE;
                    y = model.points[1].y - Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getHeight()/2.0 
                                              - bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE;
                    source->set_property("x", x);
                    source->set_property("y", y); 
                }
                else
                {
                    x = 10;
                    y = index;
                    source->set_property("x", 10);
                    source->set_property("y", index);
                }
                
                double end_x, end_y;
                double start_x;
                Goocanvas::Points points = poly->property_points().get_value();
                points.get_coordinate(4, end_x, end_y);
                points.get_coordinate(5, start_x, end_y);
                double port_w = Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getWidth();
                double port_h = Glib::RefPtr<ExternalPortModel>::cast_dynamic(source)->getHeight();
                if((x + port_w + ITEMS_MARGIE) >= end_x)
                    width = x + port_w + ITEMS_MARGIE;
                if((y + port_h + ITEMS_MARGIE) >= end_y)
                    height = y + port_h + ITEMS_MARGIE;

                double minx = start_x;
                if(x < start_x)
                {
                    minx = x - ITEMS_MARGIE;
                    text->translate(-abs(start_x-x)-ITEMS_MARGIE, 0);
                }
                points.set_coordinate(0, minx, 0);
                points.set_coordinate(1, text_w+TEXT_MARGINE*2+minx, 0);
                points.set_coordinate(2, text_w+TEXT_MARGINE*2+minx, text_h+TEXT_MARGINE);
                points.set_coordinate(3, width, text_h+TEXT_MARGINE);
                points.set_coordinate(4, width, height);
                points.set_coordinate(5, minx, height);            
                poly->property_points().set_value(points);
                Goocanvas::Points points3(3);
                points3.set_coordinate(0, width, text_h+TEXT_MARGINE);
                points3.set_coordinate(1, width, height);
                points3.set_coordinate(2, minx, height);
                shadow->property_points().set_value(points3);
            } 
            index+=40;
        }

        if(input)
           dest = findModelFromInput(input);       
        else
        {
            Glib::RefPtr<ExternalPortModel> extPort;
            bool bExist = false;
            for(int i=0; i<get_n_children(); i++)
            {
                extPort = Glib::RefPtr<ExternalPortModel>::cast_dynamic(get_child(i));
                if(extPort && compareString(extPort->getPort(), baseCon.to()))
                {
                    dest = extPort;
                    bExist = true;
                    break;
                }    
            }
            if(!bExist) 
            {
                double x,y;
                dest = ExternalPortModel::create(parentWindow, INPUTD, (*citr).to(), true);
                add_child(dest);
                size_t size = model.points.size();
                if(size > 2)
                {
                    x = model.points[size-1].x-bounds.get_x1()+ITEMS_MARGIE;
                    y = model.points[size-1].y - Glib::RefPtr<ExternalPortModel>::cast_dynamic(dest)->getHeight()/2.0 
                                            - bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE;
                    dest->set_property("x", x);
                    dest->set_property("y", y); 
                }
                else
                {
                    x = 400;
                    y = index;
                    dest->set_property("x", x);
                    dest->set_property("y", y);
                }                               
                double end_x, end_y;
                Goocanvas::Points points = poly->property_points().get_value();
                points.get_coordinate(4, end_x, end_y);
                double port_w = Glib::RefPtr<ExternalPortModel>::cast_dynamic(dest)->getWidth();
                double port_h = Glib::RefPtr<ExternalPortModel>::cast_dynamic(dest)->getHeight();
                if((x + port_w + ITEMS_MARGIE) >= end_x)
                    width = x + port_w + ITEMS_MARGIE;
                if((y + port_h + ITEMS_MARGIE) >= end_y)
                    height = y + port_h + ITEMS_MARGIE;

                points.set_coordinate(3, width, text_h+TEXT_MARGINE);
                points.set_coordinate(4, width, height);
                points.get_coordinate(5, end_x, end_y);
                points.set_coordinate(5, end_x, height);            
                poly->property_points().set_value(points);
                Goocanvas::Points points3(3);
                points3.set_coordinate(0, width, text_h+TEXT_MARGINE);
                points3.set_coordinate(1, width, height);
                points3.set_coordinate(2, end_x, height);
                shadow->property_points().set_value(points3);                    
            }    
        }
        
        if(source && dest)
        {
            Glib::RefPtr<ArrowModel> arrow = ArrowModel::create(parentWindow, source, dest, &baseCon, this);
            add_child(arrow);
            int size = model.points.size();
            for(int i=2; i<size-1; i++)
                arrow->addMidPoint(model.points[i].x-bounds.get_x1()+ITEMS_MARGIE, 
                                   model.points[i].y-bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE, i-2);            
            arrow->setSelected(false);
            if(size)
                arrow->setLabelPosition(model.points[0].x-bounds.get_x1()+ITEMS_MARGIE,
                                        model.points[0].y-bounds.get_y1()+ITEMS_MARGIE+text_h+TEXT_MARGINE);    
        }                                        
    }
}
Beispiel #30
0
void ResourceWindow::updateWidget()
{
    m_refTreeModel->clear();

    Gtk::TreeModel::Row row;
    Gtk::TreeModel::Row childrow;
//    Gtk::TreeModel::Row cchildrow;

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Name";
    row[m_Columns.m_col_value] = m_pComputer->getName();

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Description";
    row[m_Columns.m_col_value] = m_pComputer->getDescription();

    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Disable";
    if(!m_pComputer->getDisable())
    {
        row[m_Columns.m_col_value] = "No";
        row.set_value(0, Gdk::Pixbuf::create_from_data(computer_ico.pixel_data, 
                                                Gdk::COLORSPACE_RGB,
                                                true,
                                                8,
                                                computer_ico.width,
                                                computer_ico.height,
                                                computer_ico.bytes_per_pixel*computer_ico.width));
    }
    else
    {
        row[m_Columns.m_col_value] = "Yes";
        row.set_value(0, Gdk::Pixbuf::create_from_data(computer_disable_ico.pixel_data, 
                                                Gdk::COLORSPACE_RGB,
                                                true,
                                                8,
                                                computer_disable_ico.width,
                                                computer_disable_ico.height,
                                                computer_disable_ico.bytes_per_pixel*computer_disable_ico.width));
    }


    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Availablity";
    if(m_pComputer->getAvailability())
    {
        row[m_Columns.m_col_value] = "Yes";
        row.set_value(0, Gdk::Pixbuf::create_from_data(yesres_ico.pixel_data, 
                                                Gdk::COLORSPACE_RGB,
                                                true,
                                                8,
                                                yesres_ico.width,
                                                yesres_ico.height,
                                                yesres_ico.bytes_per_pixel*yesres_ico.width));
    }
    else
    {
        row[m_Columns.m_col_value] = "No";
        row.set_value(0, Gdk::Pixbuf::create_from_data(nores_ico.pixel_data, 
                                                Gdk::COLORSPACE_RGB,
                                                true,
                                                8,
                                                nores_ico.width,
                                                nores_ico.height,
                                                nores_ico.bytes_per_pixel*nores_ico.width));
        return;
    }

    // platform 
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Platform";
    row[m_Columns.m_col_value] = "";
    row.set_value(0, Gdk::Pixbuf::create_from_data(module_ico.pixel_data, 
                                            Gdk::COLORSPACE_RGB,
                                            true,
                                            8,
                                            module_ico.width,
                                            module_ico.height,
                                            module_ico.bytes_per_pixel*module_ico.width));
     
    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Name";
    childrow[m_Columns.m_col_value] = m_pComputer->getPlatform().getName();
   
    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Distribution";
    childrow[m_Columns.m_col_value] = m_pComputer->getPlatform().getDistribution();

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Release";
    childrow[m_Columns.m_col_value] = m_pComputer->getPlatform().getRelease();

    // processor
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Processor";
    row[m_Columns.m_col_value] = "";
    row.set_value(0, Gdk::Pixbuf::create_from_data(processor_ico.pixel_data, 
                                            Gdk::COLORSPACE_RGB,
                                            true,
                                            8,
                                            processor_ico.width,
                                            processor_ico.height,
                                            processor_ico.bytes_per_pixel*processor_ico.width));

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Model";
    childrow[m_Columns.m_col_value] = m_pComputer->getProcessor().getModel();
  
    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Architecture";
    childrow[m_Columns.m_col_value] = m_pComputer->getProcessor().getArchitecture();
    
    char buff[64];
    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Cores";
    sprintf(buff, "%d", (int)m_pComputer->getProcessor().getCores());
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Siblings";
    sprintf(buff, "%d", (int)m_pComputer->getProcessor().getSiblings());
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Frequency";
    sprintf(buff, "%.2f", (float)m_pComputer->getProcessor().getFrequency());
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    // CPU Load
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "CPU Load";
    row[m_Columns.m_col_value] = "";
    row.set_value(0, Gdk::Pixbuf::create_from_data(cpuload_ico.pixel_data, 
                                            Gdk::COLORSPACE_RGB,
                                            true,
                                            8,
                                            cpuload_ico.width,
                                            cpuload_ico.height,
                                            cpuload_ico.bytes_per_pixel*cpuload_ico.width));

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Load instant";
    if(compareString(m_pComputer->getPlatform().getName(), "WINDOWS"))
        sprintf(buff, "%.1f%%", (float)m_pComputer->getProcessor().getCPULoad().loadAverageInstant);
    else
    {
        float sibling = (float)m_pComputer->getProcessor().getSiblings();
        if(!sibling) sibling = 1.0F;
        float loadP = (float)(m_pComputer->getProcessor().getCPULoad().loadAverageInstant / sibling)*100.0F;
        if(loadP > 100.0F) loadP = 100.0F;
        sprintf(buff, "%.1f%%", loadP);
    }
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    float sibling = (float)m_pComputer->getProcessor().getSiblings();
    if(!sibling) sibling = 1.0F;
    float load1P = ((float)m_pComputer->getProcessor().getCPULoad().loadAverage1 / sibling)*100.0F;
    if(load1P > 100.0F) load1P = 100.0F; 
    float load5P = ((float)m_pComputer->getProcessor().getCPULoad().loadAverage5 / sibling)*100.0F;
    if(load5P > 100.0F) load5P = 100.0F; 
    float load15P = ((float)m_pComputer->getProcessor().getCPULoad().loadAverage15 / sibling)*100.0F;
    if(load15P > 100.0F) load15P = 100.0F; 
  
    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Load average 1";
    sprintf(buff, "%.1f%%", load1P);
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Load average 5";
    sprintf(buff, "%.1f%%", load5P);
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Load average 15";
    sprintf(buff, "%.1f%%", load15P);
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);
    m_TreeView.expand_row(m_refTreeModel->get_path(row), true);

    // Memory
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Memory";
    row[m_Columns.m_col_value] = "";
    row.set_value(0, Gdk::Pixbuf::create_from_data(memory_ico.pixel_data, 
                                            Gdk::COLORSPACE_RGB,
                                            true,
                                            8,
                                            memory_ico.width,
                                            memory_ico.height,
                                            memory_ico.bytes_per_pixel*memory_ico.width));

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Total space";
    sprintf(buff, "%ldKB", (long)m_pComputer->getMemory().getTotalSpace());
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Free space";
    sprintf(buff, "%ldKB", (long)m_pComputer->getMemory().getFreeSpace());
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    // Storage
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Storage";
    row[m_Columns.m_col_value] = "";
    row.set_value(0, Gdk::Pixbuf::create_from_data(storage_ico.pixel_data, 
                                            Gdk::COLORSPACE_RGB,
                                            true,
                                            8,
                                            storage_ico.width,
                                            storage_ico.height,
                                            storage_ico.bytes_per_pixel*storage_ico.width));

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Total space";
    sprintf(buff, "%ldKB", (long)m_pComputer->getStorage().getTotalSpace());
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    childrow = *(m_refTreeModel->append(row.children()));
    childrow[m_Columns.m_col_name] = "Free space";
    sprintf(buff, "%ldKB", (long)m_pComputer->getStorage().getFreeSpace());
    childrow[m_Columns.m_col_value] = Glib::ustring(buff);

    // Peripherals
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Peripheral devices";
    row[m_Columns.m_col_value] = "";
    row.set_value(0, Gdk::Pixbuf::create_from_data(device_ico.pixel_data, 
                                            Gdk::COLORSPACE_RGB,
                                            true,
                                            8,
                                            device_ico.width,
                                            device_ico.height,
                                            device_ico.bytes_per_pixel*device_ico.width));
    for(int i=0; i<m_pComputer->peripheralCount(); i++)
    {
        childrow = *(m_refTreeModel->append(row.children()));
        childrow[m_Columns.m_col_name] = m_pComputer->getPeripheralAt(i).getTypeName();
        childrow[m_Columns.m_col_value] = m_pComputer->getPeripheralAt(i).getName();
    }

    // Processes
    row = *(m_refTreeModel->append());
    row[m_Columns.m_col_name] = "Processes";
    row[m_Columns.m_col_value] = "";
    row.set_value(0, Gdk::Pixbuf::create_from_data(process_ico.pixel_data, 
                                            Gdk::COLORSPACE_RGB,
                                            true,
                                            8,
                                            process_ico.width,
                                            process_ico.height,
                                            process_ico.bytes_per_pixel*process_ico.width));

    ProcessContainer processes = m_pComputer->getProcesses();
    for(unsigned int i=0; i<processes.size(); i++)
    {
        childrow = *(m_refTreeModel->append(row.children()));
        char buff[64];
        sprintf(buff, "%d", processes[i].pid);
        childrow[m_Columns.m_col_name] = Glib::ustring(buff);
        childrow[m_Columns.m_col_value] = processes[i].command;
    }

}