Beispiel #1
0
bool data_file_section::section_new(int line, char *p_line)
{
  char token[MAX_TOKEN_LEN] = "";
  char value[MAX_TOKEN_LEN] = "";

  assert(p_line);  
  
  tokenize_line_param(p_line, token, value);
  
  if(token[0] && value[0]) {
    if(!strcasecmp(token,SECTION_NAME_NAME)) {
      name_set(value);
      source_line_set(line);
    }
    else if(!strcasecmp(token,SECTION_NAME_TYPE)) {
      strncpy(section_type,value,MAX_NAME);
      source_line_set(line);
    }
    else {
      section_new(line, p_line, token, value);
    }
    return(TRUE);
  }
  else {
    // A raw string
    section_new(line, p_line,
                token[0] ? token : NULL,
                value[0] ? value : NULL);
  }
  return(FALSE);
}
Beispiel #2
0
data_file_section::data_file_section(DATA_FILE *p_file, int line, char *p_raw_line, char *p_token, char *p_value)
  : object_list_head(NULL),
    object_list(NULL),
    line_number(line),
    raw_string(NULL),
    value_string(NULL),
    value_int(0),
    value_float(0.0f)
{
  this->p_file = p_file;
  
  mark_clear(LINE_VALUE_MARK_LOADED);  
  // Initialize values for section
  section_type[0] = '\0';  
  
  // Initialize values for line
  name_set(p_token);

  if(p_raw_line) {
    raw_string = sstrdup(p_raw_line);
  }
  
  if(p_value) {
    value_string = sstrdup(p_value);
    if(p_value[0] == '#' && isdigit(p_value[1])) {
      value_int = value_int_hexa = strtol(p_value+1,NULL,16);
      value_float = value_int;
    }
    else {
      value_int = atoi(p_value);
      value_int_hexa = strtol(p_value,NULL,16);
      value_float = atof(p_value);      
    }
  }  
}
Beispiel #3
0
generator_mesh::generator_mesh(GENERATOR *p_generator, const char *p_name)
  : generator_reference(p_generator),
    object_list(NULL),
    target_cache(this)
{
  clear();  
  name_set(p_name);
}
Beispiel #4
0
/*
{
  name = ***
  type = GENERATOR_MESH_CONFIG
}
*/
void generator_mesh::load_section_generator_config(DATA_FILE_SECTION *p_section)
{
  DATA_FILE_SECTION *p_line = p_section->section_child_get();
  if(!p_line)
    return;
  
  // Set name of this generator
  name_set(p_section->name_get());
  
  int modificator_index = -1;
  int target_index = -1;
  do {
    if(p_line->is_line()) {
      
      if(p_line->match_name("modificator")) {
        modificator_index++;
        target_index = -1;
        GENERATOR_MESH_MODIFICATOR_CONFIG *p_modificator = config.modificator_ref(modificator_index);
        strncpy(p_modificator->modificator_name, p_line->line_value_string_get(), MAX_NAME);
        p_line->line_mark_loaded();        
        continue;
      }
      else if(modificator_index >= 0) {        
        GENERATOR_MESH_MODIFICATOR_CONFIG *p_modificator = config.modificator_ref(modificator_index);

        // modificator target - for unique targets (TEXTURE/MESH)
        if(p_line->match_name("modificator_target")) {
          target_index++;
          GENERATOR_MESH_MODIFICATOR_TARGET_CONFIG *p_target = p_modificator->target_config_ref(target_index);
          p_target->target_type = modificator_target_translate(p_line->line_value_string_get());
          if(p_target->target_type == MODIFICATOR_TARGET_NONE) {            
            ppset(p_line->source_file_get(), p_line->source_line_get());
            pperror(TRUE, "'%s' is not a valid modificator target!",p_line->line_value_string_get());
            ppclear();
          }
          p_line->line_mark_loaded();
          continue;
        }
        else {
          GENERATOR_MESH_MODIFICATOR_TARGET_CONFIG *p_target = p_modificator->target_config_ref(target_index);
          
          // For other targets (BITMAP/HEIGHTMAP/AUX)
          if(p_line->match_name("modificator_target_name")) {
            strncpy(p_target->target_name, p_line->line_value_string_get(), MAX_NAME);
            p_line->line_mark_loaded();
            continue;
          }
      
          // Load repeat
          load_int(p_target->repeat,"modificator_repeat");
                    
          // Load mask
          p_target->mask.load_line(p_line, generator_get());
        }
      }
    }
  } while((p_line = p_line->section_next()));
}
Beispiel #5
0
 name_set operator()() {
     name_set A;
     name_set Fs = m_relevant;
     // unsigned i = 1;
     while (true) {
         // std::cout << "#" << i << ", p: " << m_p << "\n";
         name_set Rel;
         Fs.for_each([&](name const & F) {
                 name_set used_by = get_used_by_set(m_env, F);
                 used_by.for_each([&](name const & T) {
                         declaration const & T_decl = m_env.get(T);
                         if (A.contains(T))
                             return; // T is already in the result set
                         if (!T_decl.is_theorem() && !T_decl.is_axiom())
                             return; // we only care about axioms and theorems
                         if (ignore_T(T))
                             return; // we ignore private decls
                         double M = get_thm_score(T);
                         // std::cout << T << " : " << M << "\n";
                         if (M < m_p)
                             return; // score is to low
                         Rel.insert(T);
                         A.insert(T);
                     });
             });
         if (Rel.empty())
             break;
         // include symbols of new theorems in m_relevant
         Fs = name_set(); // reset Fs
         Rel.for_each([&](name const & T) {
                 name_set uses = get_use_set(m_env, T);
                 uses.for_each([&](name const & F) {
                         declaration const & F_decl = m_env.get(F);
                         if (F_decl.is_theorem() || F_decl.is_axiom())
                             return; // we ignore theorems occurring in types
                         if (ignore_F(F))
                             return;
                         // if (!m_relevant.contains(F))
                         //    std::cout << "new relevant: " << F << "\n";
                         m_relevant.insert(F);
                         Fs.insert(F);
                     });
             });
         m_p = m_p + (1.0 - m_p) / m_c;
     }
     return A;
 }
Beispiel #6
0
// Delete a symbol from the database
void CLibraryDb::DeleteSymbol(int SymbolID)
{
	// Build a deletion list...
	CDbLibNameSet name_set(&m_database);
	name_set.m_strFilter.Format(_T("[SymbolID]=%d"), SymbolID);
	name_set.Open();

	CString sql;
	while (!name_set.IsEOF())
	{
		sql.Format(_T("DELETE FROM [Attribute] WHERE [NameID]=%d"), name_set.m_NameID);
		m_database.Execute(sql);
		name_set.Delete();
		name_set.MoveNext();
	}

	// delete this name...
	sql.Format(_T("DELETE FROM [Symbol] WHERE [SymbolID]=%d"), SymbolID);
	m_database.Execute(sql);
}
Beispiel #7
0
Node::Node(const std::string &node_name)
{
  name_set(node_name);
} 
Beispiel #8
0
// Attach this library to a file
void CLibraryDb::Attach(const TCHAR *filename)
{
	m_name = filename;

	try
	{
		if (!m_database.IsOpen())
		{
			m_database.Open(m_name + ".mdb");
		}

		// Now read the Symbols from this database
		CDbLibNameSet name_set(&m_database);
		name_set.Open();

		while (!name_set.IsEOF())
		{

			// Is this a new symbol?
			bool is_new = m_Symbols.find(name_set.m_SymbolID) == m_Symbols.end();
			CLibraryStoreNameSet &nwSymbol = m_Symbols[name_set.m_SymbolID];

			if (is_new)
			{
				// Yes!
				nwSymbol.Blank();
				nwSymbol.lib = this;
				nwSymbol.FilePos = name_set.m_SymbolID;
				nwSymbol.ppp = static_cast<BYTE> (name_set.m_ppp);
			}

			if (name_set.m_Type == 0)
			{
				CLibraryStoreSymbol r;
				r.name = name_set.m_Name;
				r.NameID = name_set.m_NameID;
				r.reference = name_set.m_Reference;
				r.description = name_set.m_Description;
				r.name_type = static_cast<SymbolFieldType> (name_set.m_ShowName);
				r.ref_type = static_cast<SymbolFieldType> (name_set.m_ShowRef);

				if (is_new)
				{
					recordCollection records;
					records.push_back(r);
					nwSymbol.SetRecords(records);
				}
				else
				{
					nwSymbol.PushBackRecord(r);
				}

				// Now add to our map of m_Symbols
				// m_Symbols[ r.name ] = nwSymbol;
			}

			name_set.MoveNext();
		}
	} catch (CException *e)
	{
		CString s;
		CString msg;
		e->GetErrorMessage(msg.GetBuffer(256), 256, NULL);
		msg.ReleaseBuffer();
		s.Format(_T("Cannot open library %s.\r\n%s"), m_name, msg);
		AfxMessageBox(s);
		e->Delete();
		return;
	}
}
Beispiel #9
0
// Write back a symbol collection and rebuild methods file
// (i.e. partial tidy)
void CLibraryDb::SaveSymbolCollection( symbolCollection &temp_m_Symbols )
{
	std::set<int> del_set;

	// Now read the m_Symbols from this database
	CDbLibNameSet name_set( &m_database );
	name_set.Open();

	while (!name_set.IsEOF())
	{
		// Find this name in the set...
		symbolCollection::iterator it = temp_m_Symbols.begin();
		while (it != temp_m_Symbols.end())
		{
			CLibraryStoreNameSet& thisSymbol = it->second;

			// Do this for each of the names in the symbol set
			for (int i =0; i < thisSymbol.GetNumRecords(); i++)
			{
				CSymbolRecord &r = thisSymbol.GetRecord( i );

				if (r.NameID == name_set.m_NameID)
				{
					// Found it - so update it...
					name_set.Edit();
					name_set.m_Name = r.name;
					name_set.m_SymbolID = thisSymbol.FilePos;
					name_set.m_Type = 0;
					name_set.m_Reference = r.reference;
					name_set.m_ppp = thisSymbol.ppp;
					name_set.m_Description = r.description;
					name_set.m_ShowName = static_cast<int>(r.name_type);
					name_set.m_ShowRef = static_cast<int>(r.ref_type);
					name_set.Update();
					break;
				}
			}

			++ it;
		}

		// Did we find it?
		if (it == temp_m_Symbols.end())
		{
			// No, so tag it for deletion delete it...
			del_set.insert( name_set.m_SymbolID );
		}

		name_set.MoveNext();
	}

	// Now delete the m_Symbols we have tagged for deletion
	std::set<int>::iterator itd = del_set.begin();
	while (itd != del_set.end())
	{
		DeleteSymbol( *itd );
		++ itd;
	}

	ReRead();
}
Beispiel #10
0
// Write a symbol to this library
void CLibraryDb::Store(CLibraryStoreNameSet *nwSymbol, CTinyCadMultiSymbolDoc &document)
{
	// Set the busy cursor
	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));

	// First clear out all of the old names...
	if (nwSymbol->FilePos != -1)
	{
		CDbLibNameSet name_set(&m_database);
		name_set.m_strFilter.Format(_T("[SymbolID]=%d"), nwSymbol->FilePos);
		name_set.Open();

		CString sql;
		while (!name_set.IsEOF())
		{
			sql.Format(_T("DELETE FROM [Attribute] WHERE [NameID]=%d"), name_set.m_NameID);
			m_database.Execute(sql);
			name_set.Delete();
			name_set.MoveNext();
		}
	}

	// Write the symbol data into the methods file
	CStreamDb stream(&m_database, FALSE, nwSymbol->FilePos, nwSymbol->orientation);
	CXMLWriter xml(&stream);
	document.SaveXML(xml);
	stream.Flush();

	// Recover the new symbol id
	nwSymbol->FilePos = stream.m_set.m_SymbolID;

	// Do this for each of the names in the symbol set
	for (int i = 0; i < nwSymbol->GetNumRecords(); i++)
	{
		CSymbolRecord &r = nwSymbol->GetRecord(i);

		// Write back the name...
		CDbLibNameSet name_set(&m_database);

		name_set.Open();
		name_set.AddNew();

		name_set.m_Name = r.name;
		name_set.m_SymbolID = nwSymbol->FilePos;
		name_set.m_Type = 0;
		name_set.m_Reference = r.reference;
		name_set.m_ppp = nwSymbol->ppp;
		name_set.m_Description = r.description;
		name_set.m_ShowName = static_cast<int> (r.name_type);
		name_set.m_ShowRef = static_cast<int> (r.ref_type);

		name_set.Update();

		// Now recover the name this was associated with...
		name_set.MoveLast();

		// First delete the old attributes
		CString sql;
		sql.Format(_T("DELETE FROM [Attribute] WHERE [NameID]=%d"), name_set.m_NameID);
		m_database.Execute(sql);

		// Now write back the attributes...
		CDbAttributeSet attr_set(&m_database);
		attr_set.Open();
		std::vector<CSymbolField>::iterator it = r.fields.begin();
		while (it != r.fields.end())
		{
			attr_set.AddNew();
			attr_set.m_NameID = name_set.m_NameID;
			attr_set.m_AttName = (*it).field_name;
			attr_set.m_AttValue = (*it).field_default;
			attr_set.m_DisplayFlags = static_cast<int> ( (*it).field_type);
			attr_set.Update();
			++it;
		}
	}

	// Inform the design it has been saved
	document.SetModifiedFlag(FALSE);

	// Re-load the library now it has changed
	ReRead();

	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
}