Precision::Int operator"" _Precision_Int_E(char const *const raw, size_t)
{
    using str_type = Precision::Int::str_type;
    const str_type convert(raw);
    Precision::Int::size_type e_pos(convert.find('E'));
    if(e_pos == str_type::npos) e_pos = convert.find('e');
    if(e_pos == str_type::npos)
        return Precision::Int(str_type(raw));
        //Negative exponent
    if(convert[e_pos+1] == '-') return 0;

    str_type base(convert.substr(0, e_pos));
    Precision::Int::size_type exp(0);
    std::stringstream catalyst(convert.substr(e_pos+1));
    catalyst >> exp;
    Precision::Int::size_type point(base.find('.'));
    if(point == str_type::npos || point == base.size()-1){
        if(point == convert.size()-1)
            base.erase(point, 1);
        base.insert(base.size(), exp, '0');
        return base;
    }

    base.erase(point, 1);
    while(exp > 0 && point < base.size())
        --exp, ++point;
    if(point < base.size())
        base.erase(point);
    if(exp > 0)
        base.insert(base.size(), exp, '0');
    
    return base;
}
示例#2
0
static int print_setting_json(char *buf, struct setting_data *setting)
{
  int ret=0;

  if (!buf) {
    ERROR("Received NULL buffer\n");
    return -1;
  }

  /* Make sure there are at lease 128 bytes left in buffer */
  if (strlen(buf) >= PAGE_BUFFER_SIZE - 128) {
    ERROR("Buffer running out of room\n");
    return -1;
  }

  strcat(buf, "    {\n");
  sprintf(&buf[strlen(buf)], "      \"type\":\"%s\",\n", str_type(setting->type));
  sprintf(&buf[strlen(buf)], "      \"mode\":\"%s\",\n", str_mode(setting->mode));
  sprintf(&buf[strlen(buf)], "      \"setpoint\":%.1f,\n", TEMP_C(setting->setpoint));
  sprintf(&buf[strlen(buf)], "      \"comp_time\":%d,\n", setting->min_compressor_time);
  sprintf(&buf[strlen(buf)], "      \"range\":%.1f\n", TEMP_C(setting->range));
  strcat(buf, "    }");

  return ret;
}
示例#3
0
/*
    Unalloc reader
*/
Node *free_reader(Node *node)
{
    ASSERT(node, "free_reader : null environment");
    ASSERT_TYPE(node, READER, "free_reader : Bad type %s", str_type(node->type));
//	if(node->val.function->closure)
//		node->val.function->closure = free_node(node->val.function->closure);
    return NULL;
}
示例#4
0
/*
    String representation of reader
    returns linked allocated String
*/
Node *string_reader(Node *node)
{
    ASSERT(node, "string_reader : null environment");
    ASSERT_TYPE(node, READER, "string_env : Bad type %s", str_type(node->type));
//	if(node->val.function->closure)
//	{
//		Node *map = string_node(node->val.function->closure);
//		Node *res = sprintf_string("<%s macro=%s special=%s closure=%s>",
//									node->val.function->is_macro ? "yes" : "no",
//									node->val.function->is_special ? "yes" : "no",
//									str_type(FUNCTION),
//									map->val.string);
//		unlink_node(map);
//		return res;
//	}
    return sprintf_string("<%s FILE*=?>",
//						   node->val.function->is_macro ? "yes" : "no",
//						   node->val.function->is_special ? "yes" : "no",
                           str_type(FUNCTION));
}
示例#5
0
Error *error_box(char *file, int line, char *func, char *mess)
{
	Error *error = (Error *)new_node(ERROR);
	ASSERT(error, ERR_CREATE_NEW, str_type(ERROR));
	error->file = file;
    error->line = line;
    error->func = func;
    error->mess = mess;
	return unlink_new((void *)error);

	//*********************
	catch:
示例#6
0
//--------------------------------------------------------------------------
// Function:	CommonFG::openStrType
///\brief	Opens the named string datatype at this location.
///\param	name  - IN: Name of the string datatype to open
///\return	StrType instance
///\exception	H5::FileIException or H5::GroupIException
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
StrType CommonFG::openStrType( const char* name ) const
{
   // Call C function H5Topen2 to open the named datatype in this group,
   // given either the file or group id
   hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT);

   // If the datatype's opening failed, throw an exception
   if( type_id < 0 )
      throwException("openStrType", "H5Topen2 failed");

   // No failure, create and return the StrType object
   StrType str_type(type_id);
   return(str_type);
}
Precision::Float operator"" _Precision_Float_E(
    char const *const raw,
    size_t
){
    using str_type = Precision::Float::str_type;
    const str_type convert(raw);
    Precision::Float::size_type e_pos(convert.find('E'));
    if(e_pos == str_type::npos) e_pos = convert.find('e');
    if(e_pos == str_type::npos)
        return Precision::Float(str_type(raw));

    Precision::Float toreturn(convert.substr(0, e_pos));
    long long int exp(0);
    std::istringstream catalyst(convert.substr(e_pos+1));
    catalyst >> exp;
    toreturn.shift(exp);

    return toreturn;

}
示例#8
0
bool OTASCIIArmor::SaveTo_ofstream(std::ofstream& fout)
{
    String strOutput;
    std::string str_type("DATA"); // -----BEGIN OT ARMORED DATA-----

    if (WriteArmoredString(strOutput, str_type) && strOutput.Exists()) {
        // WRITE IT TO THE FILE
        //
        fout << strOutput;

        if (fout.fail()) {
            otErr << __FUNCTION__ << ": Failed saving to file.\n Contents:\n\n"
                  << strOutput << "\n\n";
            return false;
        }

        return true;
    }

    return false;
}
示例#9
0
bool OTASCIIArmor::SaveTo_ofstream(std::ofstream & fout)
{
    OTString strOutput;
    std::string str_type("DATA"); // -----BEGIN OT ARMORED DATA-----
    
    if (this->WriteArmoredString(strOutput, str_type) && strOutput.Exists())
    {
        // WRITE IT TO THE FILE
        //
        fout << strOutput.Get();

        if (fout.fail())
        {
            OTLog::vError("%s: Failed saving to file.\n Contents:\n\n%s\n\n",
                          __FUNCTION__, strOutput.Get());
            return false;
        }
        // --------------------------------------------------------------------
        return true;
    }
    // -----------------------
    return false;
}
示例#10
0
void InterfaceSim::on_add_receiver(const char *type)
{
    SimulationType t = str_type(type);
    if (t == ST_UNKNOWN) return;

    lo_address a = lo_message_get_source(m_msg);
    if (!a) return;

    char *url = lo_address_get_url(a);
    if (!url) return;

    // Physics can change object positions in any of the other
    // simulations
    if (t & ST_HAPTICS || t & ST_VISUAL)
        sendtotype(ST_PHYSICS, 0, "/world/add_receiver_url",
                   "ss", type, url);

    // Haptics can add force to objects in the physics simulation.
    if (t & ST_PHYSICS || t & ST_VISUAL)
        sendtotype(ST_HAPTICS, 0, "/world/add_receiver_url",
                   "ss", type, url);

    // Visual can send a message to haptics due to keyboard
    // shortcuts. (e.g. reset_workspace.)
    if (t & ST_HAPTICS)
        sendtotype(ST_VISUAL, 0, "/world/add_receiver_url",
                   "ss", type, url);

    // Interface can modify anything in any other simulation.
    add_receiver(0, url, t, false);

#ifdef DEBUG
    printf("[%s] add_receiver(): %s, source = %s\n", type_str(), type, url);
#endif
    free(url);
}
示例#11
0
std::ostream & Section::dump_s(std::ostream & os,
                               const DumpOptions & dump_options,
                               int level) const
{
    typedef std::pair<const Object *, const Section *> S_PAIR;
    typedef std::vector<S_PAIR> S_VECTOR;
    S_VECTOR sections;
    str_type indentation = this->indentation(level);
    //std::cout << "### default_mode=" << DefaultMode::label(dump_options.default_mode) << " -> " << std::flush;
    DefaultMode::enum_type default_mode = configment::get_default_mode(dump_options.default_mode);
    //std::cout << DefaultMode::label(default_mode) << std::endl;
    PathnameMode::enum_type pathname_mode = configment::get_pathname_mode(dump_options.pathname_mode);
    DumpOptions sub_dump_options(default_mode, pathname_mode);
    for(const_iterator i = this->begin(); i != this->end(); ++i)
    {
        const Object & pkey = i->first;
        const Object & pval = i->second;
        //std::cout << "::: " << pval << " " << pval.class_name() << std::endl;
        const Section * p_section = dynamic_cast<const Section *>(&pval.get_object());
        if(p_section != 0)
        {
            sections.push_back(std::make_pair(& pkey, p_section));
        }
        else
        {
            bool value_is_default = false;
            if(this->_default_values.has_key(pkey))
            {
                const Object & o = this->_default_values.at(pkey);
                //std::cout << "### def value:pkey=" << pkey << ", o=" << o << ", pval=" << pval << ", o==pval: " << (o == pval) << std::endl;
                if((! o.is<Section>()) && (o.operator ==(pval)))
                {
                    value_is_default = true;
                }
            }
            //else
            //{
            //    std::cout << "### no def value:pkey=" << pkey << std::endl;
            //}
            str_type comment = "";
            if(value_is_default)
            {
                switch (default_mode)
                {
                    case DefaultMode::SHOW:
                    {
                        if(pkey.is<Str>() && (pkey == str_type("__validate__") || pkey == str_type("__base_dir__")))
                        {
                            // if key is {__validate__, __base_dir__} default is skipped
                            continue;
                        }
                        else
                        {
                            // default is shown
                            break;
                        }
                    }
                    case DefaultMode::DEFAULT:
                    case DefaultMode::HIDE:
                    {
                        // default is skipped
                        continue;
                        break;
                    }
                    case DefaultMode::COMMENT:
                    {
                        if(pkey.is<Str>() && (pkey == str_type("__validate__") || pkey == str_type("__base_dir__")))
                        {
                            // if key is {__validate__, __base_dir__} default is skipped
                            continue;
                        }
                        else
                        {
                            // default is commented
                            comment = "# ";
                        }
                        break;
                    }
                }
            }
            os << indentation << comment;
            if(pkey.is<Str>())
            {
                const Str & pkey_s = dynamic_cast<const Str &>(pkey.get_object());
                //std::cout << "str " << pkey_s.repr() << " : " << pkey_s.class_name() << std::endl;
                dump_escaped_identifier_s(os, pkey_s);
            }
            else
            {
                os << pkey;
            }
            os << " = ";
            pval.grepr_s(os, ReprType::CONFIG, false, sub_dump_options, level + 1);
            os << std::endl;
        }
    }
    for(S_VECTOR::const_iterator i = sections.begin(); i != sections.end(); ++i)
    {
        const Object & pkey = *i->first;
        const Section & section = *i->second;
        os << indentation << str_type(level + 1, '[');
        if(pkey.is<Str>())
        {
            const Str & pkey_s = dynamic_cast<const Str &>(pkey.get_object());
            dump_escaped_identifier_s(os, pkey_s);
        }
        else
        {
            os << pkey;
        }
        os << str_type(level + 1, ']') << std::endl;
        section.dump_s(os, dump_options, level + 1);
    }
    return os;
}