Ejemplo n.º 1
0
CubitSimpleAttrib::CubitSimpleAttrib(const CubitString new_character_type,
                                     const CubitString new_string_data,
                                     const CubitString new_more_string_data,
                                     const int* new_integer_data,
                                     const double* new_double_data)
{
  assert(new_character_type.length() > 0);

  stringDataList.push_back(new_character_type);

  if (new_string_data.length()) {
    stringDataList.push_back(new_string_data);
  }
  
  if (new_more_string_data.length()) {
    stringDataList.push_back(new_more_string_data);
  }
  
  if(new_double_data)
    doubleDataList.push_back( *new_double_data );
  if(new_integer_data)
    intDataList.push_back( *new_integer_data );

  return;
}
Ejemplo n.º 2
0
CubitString RefEntityName::base_name(const CubitString& name)
{
  const char *pos = strchr(name.c_str(), suffixCharacter);
  if (!pos)
    return name;
  return name.substr(0, pos - name.c_str());
}
Ejemplo n.º 3
0
void CubitUtil::setenv(const CubitString& var, const CubitString& value)
{
#ifdef WIN32
  ::SetEnvironmentVariableW(CubitString::toUtf16(var).c_str(), CubitString::toUtf16(value).c_str());
#else
  ::setenv(var.c_str(), value.c_str(), 1);
#endif
}
Ejemplo n.º 4
0
char RefEntityName::get_character(const CubitString& type) const
{
  if (type.get_at(0) == 'R' || type.get_at(0) == 'r')
    return replacementCharacter;
  else if (type.get_at(0) == 'S' || type.get_at(0) == 's')
    return suffixCharacter;  
  else {
    PRINT_ERROR("Invalid character type '%s', must be "
		"'replacement' or 'suffix'\n", type.c_str());
    return '#';
  }
}
Ejemplo n.º 5
0
// returns CUBIT_TRUE if the two names have the same base name (i.e.
// the same name before the first suffixCharacter
CubitBoolean RefEntityName::same_base_name(const CubitString &name1,
                                           const CubitString &name2)
{
  const char *pos1 = strchr(name1.c_str(), suffixCharacter);
  const char *pos2 = strchr(name2.c_str(), suffixCharacter);

    // check for replacement character in one but not the other
  int length1, length2;
  if (pos1 == NULL)
    length1 = strlen(name1.c_str());
  else
    length1 = pos1 - name1.c_str();

  if (pos2 == NULL)
    length2 = strlen(name2.c_str());
  else
    length2 = pos2 - name2.c_str();

    // if the lengths are different, the base names are also different
  if (length1 != length2)
    return CUBIT_FALSE;

  if (strncmp(name1.c_str(), name2.c_str(), length1) == 0)
    return CUBIT_TRUE;
  else
    return CUBIT_FALSE;
}
Ejemplo n.º 6
0
void RefEntityName::set_character(char rep, const CubitString &type)
{
  if (is_valid_char(rep)) {
    if (type.get_at(0) == 'R' || type.get_at(0) == 'r')
      replacementCharacter = rep;
    else if (type.get_at(0) == 'S' || type.get_at(0) == 's')
      suffixCharacter = rep;
    else
      PRINT_ERROR("Invalid character type '%s', must be "
		  "'replacement' or 'suffix'\n", type.c_str());
  } else {
    PRINT_ERROR("Character '%c' is not a valid entity name character\n",
		rep);
  }
}
Ejemplo n.º 7
0
void CubitMessage::output_debug_information(CubitString &match)
{
  int count = 0;
  for (int i=1; i <= number_of_debug_flags(); i++) {
    char *tmp = CubitUtil::util_strdup((char*)(debugFlag[i].description));
    if (tmp && strlen(tmp) > 0) {
      CubitString debug_description(tmp);
      debug_description.to_lower();
      if (debug_description.find(match, 0) < debug_description.length()) {
	if (count == 0) {
	  PRINT_INFO("Debug Flag Settings "
		     "(flag number, setting, output to, description):\n");
	}
	debugFlag[i].output();
	count++;
      }
    }
    CubitUtil::util_strdup_free(tmp);
  }
  if (count == 0) {
    PRINT_WARNING("No debug descriptions contain the "
		  "substring '%s'\n", match.c_str());
  }
  PRINT_INFO("\n");
}
Ejemplo n.º 8
0
size_t CubitString::find(const CubitString& s, size_t pos) const
{
  assert(pos < length());
  char *p = strstr(rep->chars,s.c_str());
  if (p)
    return pos + (p - rep->chars);
  return MAX_POS;
}
Ejemplo n.º 9
0
// given a relative or absolute path, make it absolute
static std::string make_path_absolute(const std::string& p)
{
  std::string ret;
  if(!p.empty())
  {
    if ( CubitFileUtil::is_absolute(p.c_str()) )
    {
      ret = p;
    }
    else
    {
      // if any '/' character is in it, its relative to current directory
      CubitString wd;
      CubitFileUtil::get_current_working_directory(wd);
      ret = wd.c_str();
      ret += path_separator;
      ret += p;
    }
  }
  return ret;
}
Ejemplo n.º 10
0
CubitStatus RefEntityName::clean(CubitString &raw_name)
{
  if (raw_name == "")
    return CUBIT_FAILURE;

    // A valid name consists of alphanumeric characters plus '.', '_', '-', or '@'
  CubitStatus found_invalid_character = CUBIT_FAILURE;

  // Initial character must be alphabetic or "_".
  char c = raw_name.get_at(0);
  if (!is_valid_first_char(c)) {
    if (is_valid_first_char(get_character("replace")))
      raw_name.put_at(0, get_character("replace"));
    else
      raw_name.put_at(0, '_');
    found_invalid_character = CUBIT_SUCCESS;
  }
  
  for (unsigned int i = 1; i < raw_name.length(); i++) {
    c = raw_name.get_at(i);
    if (!is_valid_char(c)) {
      found_invalid_character = CUBIT_SUCCESS;
      raw_name.put_at(i, get_character("replace"));
    }
  }
  return found_invalid_character;
}
Ejemplo n.º 11
0
CubitString CubitUtil::get_temporary_filename()
{

  CubitString ret_str;

#ifdef WIN32
  
  //get a place to put the temporary file
  CubitString temp_path = get_temp_directory();

  // make an empty temporary and return the name for it
  wchar_t temp_file_name[MAX_PATH];
  if( GetTempFileNameW(CubitString::toUtf16(temp_path.c_str()).c_str(), L"CBT", 0, temp_file_name) != 0 )
    ret_str = CubitString::toUtf8(temp_file_name); 

#else

  CubitString tmpdir = get_temp_directory();
  const char* filepattern = "CBT.XXXXXX";
    //needs to be two longer because of the "/"?
  char *temp_file_name = new char[tmpdir.length() + strlen(filepattern) + 2];
  sprintf(temp_file_name, "%s/%s", tmpdir.c_str(), filepattern);

  // make an empty file and return the name for it
  int fd = mkstemp(temp_file_name);
  if( fd != -1 )
  {
    ret_str = temp_file_name; 
    // release the open done by mkstemp,
    // temporary file still exists
    close(fd);
  }
  delete [] temp_file_name;

#endif

  return ret_str;
}
Ejemplo n.º 12
0
void main() {
CubitString a = "Test ";
CubitString b = "String Class";
CubitString blank(' ');

CubitString c = a + b;
c+= b;
CubitString e = c;
CubitString f = c;
CubitString g = c;
g.put_at(1, 'Z');
cout << "G = " << g << endl;
cout << "C = " << c << endl;

c.put_at(1, 'X');
CubitString d = b;
d.put_at(1, 'Y');
}
Ejemplo n.º 13
0
void RefEntityName::set_suffix_setting(CubitString rep)
{
  const char* tmp = rep.c_str();
  suffixCharacter = tmp[0];
}
Ejemplo n.º 14
0
CubitStatus RefEntityName::generate_unique_name(CubitString &name)
{
  // The method used to generate a unique name is to append
  // 'suffixCharacter' and
  // a letter from A-Z, a-z, or 0-9 to the end of name.
  // If none of these produce a unique name, CUBIT_FALSE is returned.

  CubitString alphabet =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  CubitString suffix("  ");
  suffix.put_at(0, suffixCharacter);
  
  CubitString internal = name;

  // See if there is an suffixCharacter sign in name already. If so, is it
  // the second to the last character in the string.
  if (name.length() < 2 ||
      name.get_at(name.length()-2) != suffixCharacter) {
    // Name does not contain suffixCharacter at correct location, add one on.
    internal += suffix;
  }
  
  CubitStatus found_unique = CUBIT_FAILURE;
  int continue_trying = CUBIT_TRUE;

  while (!found_unique && continue_trying) {
	 
    continue_trying = CUBIT_FALSE;
    int name_length = internal.length();
    unsigned int number_tested = 0;
    for (unsigned int i=0; i < alphabet.length(); i++) {
      internal.put_at(name_length-1, (char)alphabet.get_at(i));
      if (!nameEntityList.move_to(internal)) {
	found_unique = CUBIT_SUCCESS;
	break;
      }
      number_tested++;
    }

    if (number_tested == alphabet.length()) {
      // All suffixes used. Add another suffixCharacter and try again
      // Name will look like 'Name@@1' or 'Name@@@1'...
      // Find LAST suffixCharacter in name
      int ch;
      for (ch = (int)(internal.length())-1; ch >= 0; ch--) {
	if (internal.get_at(ch) == suffixCharacter) {
	  break;
	}
      }
      if (internal.get_at(ch) == suffixCharacter) {
	// Add another suffixCharacter at ch+1
	// Assured that position ch+1 exists or we wouldn't be here
	internal.put_at(ch+1, suffixCharacter);
	if (ch+2 < (int)internal.length())
	  internal.put_at(ch+2, ' ');
	else
	  internal += " ";
	continue_trying = CUBIT_TRUE;
      }
    }
  }
  
  if (found_unique)
    name = internal;

  return found_unique;
}
Ejemplo n.º 15
0
bool operator>( const CubitString& s1, const CubitString& s2 )
{ return strcmp( s1.c_str(), s2.c_str() ) > 0; }
Ejemplo n.º 16
0
CubitString CubitUtil::getenv(const CubitString& var)
{
  return CubitString(::getenv(var.c_str()));
}
Ejemplo n.º 17
0
CubitStatus RefEntityName::add_refentity_name(RefEntity *entity,
                                              CubitString &name,
                                              bool update_attribs,
                                              bool check_name_validity)
{
  if (name == "")
    return CUBIT_FAILURE;
  
  CubitString in_name = name;
  bool warn_name_change = false;
  
  if (check_name_validity)
  {
    if (clean(name))
    {
      // Assign the invalid name anyway, then continue on and
      // assign the modified name.
      add_refentity_name(entity, in_name, false, false);
      warn_name_change = true;
    }
  }
  
  if (nameEntityList.move_to(name))
  {
    RefEntity *old_entity = nameEntityList.get()->value();
    if (old_entity == entity)
    {
        // Tried to assign same name to entity
      if ( DEBUG_FLAG(92) ) 
      {
        PRINT_INFO("Entity name '%s' already assigned to %s %d\n",
                   name.c_str(), 
                   entity->class_name(), entity->id());
        return CUBIT_FAILURE;
      }
      return CUBIT_SUCCESS;
    }
    else
    {
        // Tried to assign existing name to another entity
      if ( DEBUG_FLAG(92) )
        PRINT_WARNING("Entity name '%s' for %s %d is already used by %s %d\n",
                      name.c_str(),
                      entity->class_name(), entity->id(),
                      old_entity->class_name(), old_entity->id());
      if (get_fix_duplicate_names())
      {
        if (generate_unique_name(name))
        {
          if (warn_name_change)
          {
            PRINT_WARNING("Entity name '%s' can't be used in commands.\n"
                 "         Additional name '%s' assigned.\n",
              in_name.c_str(), name.c_str());
          }
          if ( DEBUG_FLAG(92) )
            PRINT_WARNING("\t%s %d name changed to '%s'\n",
            entity->class_name(), entity->id(), name.c_str());
          return add_refentity_name(entity, name, update_attribs, false);
        }
      }
      return CUBIT_FAILURE;
    }
  }

  if (warn_name_change)
  {
    PRINT_WARNING("Entity name '%s' can't be used in commands.\n"
      "         Additional name '%s' assigned.\n",
      in_name.c_str(), name.c_str());
  }

  RefEntityNameMap *entity_name =
    new RefEntityNameMap(name, entity);
  nameEntityList.insert(entity_name);
  
  if (update_attribs == CUBIT_TRUE)
  {
      // now tell the entity to update its name attribute
    CubitAttrib *attrib = entity->get_cubit_attrib(CA_ENTITY_NAME);
      // force update by resetting update flag
    attrib->has_updated(CUBIT_FALSE);
    attrib->update();
  }
  
  return CUBIT_SUCCESS;
}
Ejemplo n.º 18
0
void RefEntityName::set_replacement_setting(CubitString rep)
{
  const char* tmp = rep.c_str();
  replacementCharacter = tmp[0];
}
Ejemplo n.º 19
0
CubitStatus RefEntityName::add_refentity_name(RefEntity *entity,
                                              DLIList<CubitString> &names,
                                              bool update_attribs, 
                                              bool check_name_validity)
{
  names.reset();
  //int num_new_names = names.size();

  DLIList<CubitString> new_names;
  
  for (int i=0; i<names.size(); i++)
  {
    CubitString name = names[i];
    CubitString in_name = name;
    CubitBoolean warn_name_change = CUBIT_FALSE;
    
      // first, clean the name
    if (check_name_validity)
    {
      if (clean(name))
      {
        // assign original name anyway, then
        // continue on and assign modified name.
        add_refentity_name(entity, in_name, false, false);
        warn_name_change = CUBIT_TRUE;
      }
    }
      // now, check for valid name
    CubitBoolean name_valid = CUBIT_FALSE;
    
    if (name == "")
    {
        // blank name entered - do nothing
    }
    
    else if (nameEntityList.move_to(name) &&
             nameEntityList.get()->value() == entity)
    {
        // Tried to assign same name to entity
      if ( DEBUG_FLAG(92) ) 
      {
          // check to see if it's the same as this entity's default name,
          // if so, it probably came in on an attribute, and we don't need
          // to hear about it; otherwise, write the warning
        CubitString def_name;
        entity->generate_default_name(def_name);
        if (name != def_name)
          PRINT_INFO("Entity name '%s' already assigned to %s %d\n",
                     name.c_str(), 
                     entity->class_name(), entity->id());
      }
    }
    else if (nameEntityList.move_to(name) &&
             nameEntityList.get()->value() != entity)
    {
        // Tried to assign existing name to another entity
      PRINT_DEBUG_92( "Entity name '%s' for %s %d is already used by %s %d\n",
                  name.c_str(), entity->class_name(), entity->id(),
                  nameEntityList.get()->value()->class_name(),
                  nameEntityList.get()->value()->id());
      
        // either we fix it and keep it, or we don't and get rid of it
      name_valid = CUBIT_FALSE;
      if (get_fix_duplicate_names())
      {
        if (generate_unique_name(name))
        {
          PRINT_DEBUG_92( "\t%s %d name changed to '%s'\n",
                          entity->class_name(), entity->id(), name.c_str());
          if(warn_name_change)
          {
            PRINT_WARNING("Entity name '%s' can't be used in commands.\n"
                 "         Additional name '%s' assigned.\n",
              in_name.c_str(), name.c_str());
          }
          
          name_valid = CUBIT_TRUE;
        }
      }
    }
    else
    {
      if(warn_name_change)
      {
        PRINT_WARNING("Entity name '%s' can't be used in commands.\n"
          "         Additional name '%s' assigned.\n",
          in_name.c_str(), name.c_str());
      }
      
        // else the name must be valid
      name_valid = CUBIT_TRUE;
    }
    
    if (name_valid == CUBIT_TRUE)
    {
        // name is valid
      if (name != in_name)
          // name was changed; change in name list too
        names[i] = name;

        // save this name to later
      new_names.append(names[i]);
    }
  }
  
  if (new_names.size() > 0)
  {
      // there are some valid, new names; add them, then update attribute
    new_names.reset();
    
    CubitString name;
    for (int i = new_names.size(); i > 0; i--)
    {
      name = new_names.get_and_step();
      if (nameEntityList.move_to(name) &&
          nameEntityList.get()->value() == entity) {
            PRINT_DEBUG_92("Already have name %s for %s %d.\n",
                           name.c_str(), entity->class_name(), entity->id());
      }
      
      else {
        nameEntityList.insert(new RefEntityNameMap(name, entity));
      }
    }
    
    if (update_attribs == CUBIT_TRUE)
    {
        // now tell the entity to update its name attribute
      CubitAttrib *attrib = entity->get_cubit_attrib(CA_ENTITY_NAME);
        // force update by resetting update flag
      attrib->has_updated(CUBIT_FALSE);
      attrib->update();
    }
  }
  
  return CUBIT_SUCCESS;
}