const std::string& CmdServerStart::execute( const std::vector< std::string >& arguments )
{
    _cmdResult = "";
    if ( arguments.size() < 1 )
    {
        _cmdResult = getUsage();
        return _cmdResult;
    }

    // get the full binary path
    std::string cmd = yaf3d::Application::get()->getFullBinPath();
    std::string levelfile = arguments[ 0 ];
    std::string arg1( "-server" );
    std::string arg2( "-level" );
    std::string arg3( levelfile );

    // use utility function to start the server
    std::string args = arg1 + "  " + arg2 + "  " + arg3;
    YAF3D_SPAWN_PROC_ID serverProcHandle = yaf3d::spawnApplication( cmd, args );

    if ( serverProcHandle )
        _cmdResult = "trying to start server with level file '" + levelfile + "'.";
    else
        _cmdResult = "* error starting server with level file '" + levelfile + "'.";

    return _cmdResult;
}
// ----------------------------------------------------------------------
double f_3g(double *x, double *par) {
  // par[0] -> const
  // par[1] -> mean
  // par[2] -> sigma
  // par[3] -> const
  // par[4] -> mean
  // par[5] -> sigma
  // par[6] -> const
  // par[7] -> mean
  // par[8] -> sigma
  Double_t arg1(0.), arg2(0.), arg3(0.), fitval1(0.), fitval2(0.), fitval3(0.); 
  if (par[2] > 0) {
    arg1 = (x[0] - par[1]) / par[2];
    fitval1 =  par[0]*TMath::Exp(-0.5*arg1*arg1);
  }
  if (par[5] > 0.) {
    arg2 = (x[0] - par[4]) / par[5];
    fitval2 =  par[3]*par[0]*TMath::Exp(-0.5*arg2*arg2);
  }
  if (par[8] > 0.) {
    arg3 = (x[0] - par[7]) / par[8];
    fitval3 =  par[6]*par[0]*TMath::Exp(-0.5*arg3*arg3);
  }
  Double_t fitval = fitval1 + fitval2 + fitval3;
  return fitval;
}
Example #3
0
int main(int argc, char* argv[])
{
	switch (argc)
	{
		case 3:
			strcpy(buffer1, argv[1]);
			strcpy(buffer2, argv[2]);
			
			arg2(buffer1, buffer2);
			break;
		
		case 4:
			strcpy(buffer1, argv[1]);
			strcpy(buffer2, argv[2]);
			sscanf(argv[3], "%d", &buffer3);
			
			arg3(buffer1, buffer2, buffer3);
			break;
		
		default:		
			arg0();
			break;
	}
	return(0);
}
Example #4
0
void test_values()
{
	RPN::Context cxt;
	
	//Constant node (boring)
	cxt.insert("c", new RPN::ConstantNode(42));
	insist_equal(evaluate("c", cxt), 42.0);
	
	//Variable node
	double x;
	cxt.insert("x", new RPN::VariableNode(&x));
	
	x = 17;
	RPN::Expression var("x", cxt);
	insist_equal(var.evaluate(), 17.0);
	
	x = 23;
	insist_equal(var.evaluate(), 23.0);
	
	//Expression node
	cxt.insert("e", new RPN::ExpressionNode(&var));
	insist_equal(evaluate("e", cxt), 23.0);
	
	//Argument node
	RPN::Evaluator eval;
	
	//One argument...
	cxt.insert("arg11", new RPN::ArgumentNode(1, 1));
	RPN::Expression arg1("arg11", cxt, 1);
	
	eval.push(12);
	insist_equal(arg1.evaluate(eval), 12.0);
	insist_equal(arg1.evaluate(7.5), 7.5);
	insist_zero(eval.count());
	
	//Two arguments...
	cxt.insert("arg12", new RPN::ArgumentNode(-2));
	cxt.insert("arg22", new RPN::ArgumentNode(-1));
	RPN::Expression arg2("arg12 + arg22", cxt, 2);
	
	eval.push(13);
	eval.push(14);
	insist_equal(arg2.evaluate(eval), 27.0);
	insist_equal(arg2.evaluate(7.5, 8.5), 16.0);
	insist_zero(eval.count());
	
	//Three arguments...
	cxt.insert("arg13", new RPN::ArgumentNode(1, 3));
	cxt.insert("arg23", new RPN::ArgumentNode(-2));
	cxt.insert("arg33", new RPN::ArgumentNode(3, 3));
	RPN::Expression arg3("arg13 + arg23 + arg33", cxt, 3);
	
	eval.push(101);
	eval.push(202);
	eval.push(303);
	insist_equal(arg3.evaluate(eval), 606.0);
	insist_equal(arg3.evaluate(1, 2, 3), 6.0);
	insist_zero(eval.count());
}
EXPORT_C TInt RMemSpySession::GetInfoItemType( TInt aIndex, TThreadId aId, TMemSpyThreadInfoItemType &aType )
	{
	TPckgBuf<TInt> arg1( aIndex );
	TPckgBuf<TThreadId> arg2( aId );
	TPckgBuf<TMemSpyThreadInfoItemType> arg3;
	TIpcArgs args( &arg1, &arg2, &arg3 );
		
	TInt error = SendReceive( EMemSpyClientServerOpGetInfoItemType, args );
	
	aType = arg3();
	
	return error;
	}
Example #6
0
Variant c_ErrorException::ifa___construct(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::ifa_dummy(mcp, count, INVOKE_FEW_ARGS_PASS_ARGS, ifa___construct, coo_ErrorException);
  }
  c_ErrorException *self ATTRIBUTE_UNUSED (static_cast<c_ErrorException*>(mcp.obj));
  if (UNLIKELY(count > 5)) return throw_toomany_arguments("ErrorException::__construct", 5, 2);
  if (count <= 0) return (self->t___construct(), null);
  CVarRef arg0(a0);
  if (count <= 1) return (self->t___construct(arg0), null);
  CVarRef arg1(a1);
  if (count <= 2) return (self->t___construct(arg0, arg1), null);
  CVarRef arg2(a2);
  if (count <= 3) return (self->t___construct(arg0, arg1, arg2), null);
  CVarRef arg3(a3);
  if (count <= 4) return (self->t___construct(arg0, arg1, arg2, arg3), null);
  CVarRef arg4(a4);
  return (self->t___construct(arg0, arg1, arg2, arg3, arg4), null);
}
Example #7
0
Variant NEVER_INLINE c_SoapFault::ifa___construct(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::ifa_dummy(mcp, count, INVOKE_FEW_ARGS_PASS_ARGS, ifa___construct, coo_SoapFault);
  }
  c_SoapFault *self ATTRIBUTE_UNUSED (static_cast<c_SoapFault*>(mcp.obj));
  if (UNLIKELY(count < 2)) return throw_wrong_arguments("SoapFault::__construct", count, 2, 6, 2);
  CVarRef arg0(a0);
  CVarRef arg1(a1);
  if (count <= 2) return (self->t___construct(arg0, arg1), null);
  CVarRef arg2(a2);
  if (count <= 3) return (self->t___construct(arg0, arg1, arg2), null);
  CVarRef arg3(a3);
  if (count <= 4) return (self->t___construct(arg0, arg1, arg2, arg3), null);
  CVarRef arg4(a4);
  if (count <= 5) return (self->t___construct(arg0, arg1, arg2, arg3, arg4), null);
  CVarRef arg5(a5);
  return (self->t___construct(arg0, arg1, arg2, arg3, arg4, arg5), null);
}
Example #8
0
// private 
// runs in main thread
bool
MovieLoader::processCompletedRequest(const Request& r)
{
    //GNASH_REPORT_FUNCTION;

    boost::intrusive_ptr<movie_definition> md;
    if (!r.getCompleted(md)) return false; // not completed yet

    const std::string& target = r.getTarget();
    DisplayObject* targetDO = _movieRoot.findCharacterByTarget(target);
    as_object* handler = r.getHandler();

    if (!md) {

        if (targetDO && handler) {
            // Signal load error
            // Tested not to happen if target isn't found at time of loading
            //

            as_value arg1(getObject(targetDO));

            // FIXME: docs suggest the string can be either "URLNotFound" or
            // "LoadNeverCompleted". This is neither of them:
            as_value arg2("Failed to load movie or jpeg");

            // FIXME: The last argument is HTTP status, or 0 if no connection
            // was attempted (sandbox) or no status information is available
            // (supposedly the Adobe mozilla plugin).
            as_value arg3(0.0);

            callMethod(handler, NSV::PROP_BROADCAST_MESSAGE, "onLoadError",
                    arg1, arg2, arg3);
        }
        return true; // nothing to do, but completed
    }

    const URL& url = r.getURL();

	Movie* extern_movie = md->createMovie(*_movieRoot.getVM().getGlobal());
	if (!extern_movie) {
		log_error(_("Can't create Movie instance "
                    "for definition loaded from %s"), url);
		return true; // completed in any case...
	}

	// Parse query string
	MovieClip::MovieVariables vars;
	url.parse_querystring(url.querystring(), vars);
    extern_movie->setVariables(vars);

    if (targetDO) {
        targetDO->getLoadedMovie(extern_movie);
    }
    else {
        unsigned int levelno;
        const int version = _movieRoot.getVM().getSWFVersion();
        if (isLevelTarget(version, target, levelno)) {
            log_debug(_("processCompletedRequest: _level loading "
                    "(level %u)"), levelno);
	        extern_movie->set_depth(levelno + DisplayObject::staticDepthOffset);
            _movieRoot.setLevel(levelno, extern_movie);
        }
        else {
            log_debug("Target %s of a loadMovie request doesn't exist at "
                  "load complete time", target);
            return true;
        }
    }

    if (handler && targetDO) {
        // Dispatch onLoadStart
        // FIXME: should be signalled before starting to load
        //        (0/-1 bytes loaded/total) but still with *new*
        //        display object as target (ie: the target won't
        //        contain members set either before or after loadClip.
        callMethod(handler, NSV::PROP_BROADCAST_MESSAGE, "onLoadStart",
            getObject(targetDO));

        // Dispatch onLoadProgress
        // FIXME: should be signalled on every readNonBlocking()
        //        with a buffer size of 65535 bytes.
        //
        size_t bytesLoaded = md->get_bytes_loaded();
        size_t bytesTotal = md->get_bytes_total();
        callMethod(handler, NSV::PROP_BROADCAST_MESSAGE, "onLoadProgress",
            getObject(targetDO), bytesLoaded, bytesTotal);

        // Dispatch onLoadComplete
        // FIXME: find semantic of last arg
        callMethod(handler, NSV::PROP_BROADCAST_MESSAGE, "onLoadComplete",
            getObject(targetDO), as_value(0.0));


        // Dispatch onLoadInit
        
        // This event must be dispatched when actions
        // in first frame of loaded clip have been executed.
        //
        // Since getLoadedMovie or setLevel above will invoke
        // construct() and thus queue all actions in first
        // frame, we'll queue the
        // onLoadInit call next, so it happens after the former.
        //
        std::auto_ptr<ExecutableCode> code(
                new DelayedFunctionCall(targetDO, handler,
                    NSV::PROP_BROADCAST_MESSAGE, 
                    "onLoadInit", getObject(targetDO)));

        getRoot(*handler).pushAction(code, movie_root::PRIORITY_DOACTION);
    }

    return true;

}
Example #9
0
void testUint32()
{

    {
        // Test for Null value constructor and toString
        Uint32Arg argNull;

        PEGASUS_TEST_ASSERT(argNull.isNull() == true);
        String x =  argNull.toString();
        VCOUT << x << endl;
        PEGASUS_TEST_ASSERT(x == String("NULL"));

        // set value and test for that value
        Uint32Arg arg(10);

        VCOUT << arg.toString() << endl;
        PEGASUS_TEST_ASSERT(arg.toString() == String("10"));

        PEGASUS_TEST_ASSERT(arg.getValue() == 10);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);

        // test resetting to Null
        arg.setNullValue();
        PEGASUS_TEST_ASSERT(arg.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg.isNull() == true);

        VCOUT << arg.toString() << endl;

        PEGASUS_TEST_ASSERT(arg.toString() == String("NULL"));
    }

    {
        // test starting with null constructor and setting value
        Uint32Arg arg;

        PEGASUS_TEST_ASSERT(arg.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg.isNull() == true);

        arg.setValue(10);
        PEGASUS_TEST_ASSERT(arg.getValue() == 10);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);
    }

    {
        // test copy operations.
        Uint32Arg arg;
        PEGASUS_TEST_ASSERT(arg.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg.isNull() == true);

        Uint32Arg arg2 = arg;
        PEGASUS_TEST_ASSERT(arg2.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg2.isNull() == true);

        arg.setValue(10);
        PEGASUS_TEST_ASSERT(arg.getValue() == 10);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);

        Uint32Arg arg3 = arg;
        PEGASUS_TEST_ASSERT(arg3.getValue() == 10);
        PEGASUS_TEST_ASSERT(arg3.isNull() == false);
    }

    {
        // test setting to max Uint32 value
        Uint32Arg arg;
        arg.setValue(4294967295UL);

        PEGASUS_TEST_ASSERT(arg.getValue() == 4294967295UL);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);

        VCOUT << arg.toString() << endl;
        PEGASUS_TEST_ASSERT(arg.toString() == String("4294967295"));
    }
    {
        // test equal function
        Uint32Arg arg1;
        Uint32Arg arg2;
        PEGASUS_TEST_ASSERT(arg1.equal(arg2));
        PEGASUS_TEST_ASSERT(arg1 == arg2);
        Uint32Arg arg3(987654);
        Uint32Arg arg4(987654);
        PEGASUS_TEST_ASSERT(arg3.equal(arg4));
        PEGASUS_TEST_ASSERT(arg3 == arg4);
        PEGASUS_TEST_ASSERT(!arg1.equal(arg3));
        PEGASUS_TEST_ASSERT(!(arg1 == arg3));
        arg4.setValue(2);
        PEGASUS_TEST_ASSERT(!arg3.equal(arg4));
        PEGASUS_TEST_ASSERT(!(arg3 == arg4));
    }

    // test as parameter of a call.
    foo32(1234);
}
Example #10
0
void testUint64()
{
    {
        // test constructors and setting value and null
        Uint64Arg argNull;
        String x =  argNull.toString();
        VCOUT << x << endl;
        PEGASUS_TEST_ASSERT(x == String("NULL"));

        //PEGASUS_TEST_ASSERT(x == "NULL");

        Uint64Arg arg(102958);

        PEGASUS_TEST_ASSERT(arg.getValue() == 102958);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);

        VCOUT << arg.toString() << endl;
        PEGASUS_TEST_ASSERT(arg.toString() == String("102958"));

        arg.setNullValue();
        PEGASUS_TEST_ASSERT(arg.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg.isNull() == true);

        String val = arg.toString();
        VCOUT << val << endl;

        PEGASUS_TEST_ASSERT(val == String("NULL"));
    }

    {
        // test starting with Null constructor and setting value
        Uint64Arg arg;

        PEGASUS_TEST_ASSERT(arg.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg.isNull() == true);

        arg.setValue(10);
        PEGASUS_TEST_ASSERT(arg.getValue() == 10);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);
    }
   {
        // test copy operations.
        Uint64Arg arg;
        PEGASUS_TEST_ASSERT(arg.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg.isNull() == true);

        Uint64Arg arg2 = arg;
        PEGASUS_TEST_ASSERT(arg2.getValue() == 0);
        PEGASUS_TEST_ASSERT(arg2.isNull() == true);

        arg.setValue(10);
        PEGASUS_TEST_ASSERT(arg.getValue() == 10);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);

        Uint64Arg arg3 = arg;
        PEGASUS_TEST_ASSERT(arg3.getValue() == 10);
        PEGASUS_TEST_ASSERT(arg3.isNull() == false);
    }

    {
        // test setting to max Uint32 value
        Uint64Arg arg;
        arg.setValue(18446744073709551615ULL);

        PEGASUS_TEST_ASSERT(arg.getValue() == 18446744073709551615ULL);
        PEGASUS_TEST_ASSERT(arg.isNull() == false);

        VCOUT << arg.toString() << endl;
        PEGASUS_TEST_ASSERT(arg.toString() == String("18446744073709551615"));
    }
    {
        // test equal function
        Uint64Arg arg1;
        Uint64Arg arg2;
        PEGASUS_TEST_ASSERT(arg1.equal(arg2));
        PEGASUS_TEST_ASSERT(arg1 == arg2);
        Uint64Arg arg3(987654);
        Uint64Arg arg4(987654);
        PEGASUS_TEST_ASSERT(arg3.equal(arg4));
        PEGASUS_TEST_ASSERT(arg3 == arg4);
        PEGASUS_TEST_ASSERT(!arg1.equal(arg3));
        PEGASUS_TEST_ASSERT(!(arg1 == arg3));
        arg4.setValue(2);
        PEGASUS_TEST_ASSERT(!arg3.equal(arg4));
        PEGASUS_TEST_ASSERT(!(arg3 == arg4));
    }

    foo64(12345678);
}
static int main_(int argc, char** argv)
{
    // 0 - nothing
    // 1 - ratios only, in the form of "t:v; t:v; ..."
    // 2 - ratios only, one-per-line
    // 3 - as is

    int verbosity;

    XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);


#ifndef NDEBUG
    unsigned ITERATIONS =   3;
    unsigned WARMUPS    =   1;
#else /* ? !NDEBUG */
    unsigned ITERATIONS =   100000;
    unsigned WARMUPS    =   2;
#endif /* !NDEBUG */
    size_t   length     =   0;

    platformstl::performance_counter                counter;
    platformstl::performance_counter::interval_type tm_Streams          =   1;
    platformstl::performance_counter::interval_type tm_IOStreams        =   1;
    platformstl::performance_counter::interval_type tm_CString_Format   =   1;
    platformstl::performance_counter::interval_type tm_Boost            =   1;
    platformstl::performance_counter::interval_type tm_Loki             =   1;
    platformstl::performance_counter::interval_type tm_FF_Format        =   1;
    platformstl::performance_counter::interval_type tm_FF_Write         =   1;
#ifdef FASTFORMAT_USE_WIDE_STRINGS
//    std::wstring                                    arg0                =   L"abc";
//    const wchar_t                                   arg1[]              =   L"def";
//    stlsoft::simple_wstring                         arg2                =   L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#else /* ? FASTFORMAT_USE_WIDE_STRINGS */
    std::string                                     arg0                =   "abc";
    const char                                      arg1[]              =   "def";
    stlsoft::simple_string                          arg2                =   "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    std::string                                     arg3(10, '~');
    stlsoft::simple_string                          arg4                =   "abcdefghijklmnopqrstuvwxyz";
    std::string                                     arg5                =   "0123456789";
    const char                                      arg6[]              =   "                                                                        ";
    stlsoft::string_view                            arg7(&arg6[0], STLSOFT_NUM_ELEMENTS(arg6) - 1);
    std::string                                     arg8(1000, '#');
    stlsoft::string_view                            arg9                =   arg7;
#endif /* FASTFORMAT_USE_WIDE_STRINGS */

    // Test Identifier

    std::string TestId = PANTHEIOS_FE_PROCESS_IDENTITY;

    // IOStreams

    { for(unsigned j = 0; j < WARMUPS; ++j)
    {
        length = 0;
        counter.start();
        { for(unsigned i = 0; i < ITERATIONS; ++i)
        {
#ifdef FASTFORMAT_USE_WIDE_STRINGS
            std::wstringstream   ss;
#else /* ? FASTFORMAT_USE_WIDE_STRINGS */
            std::stringstream   ss;
#endif /* FASTFORMAT_USE_WIDE_STRINGS */

            ss << arg0 << arg1 << arg2 << arg3 << arg4 << arg5 << arg6 << arg7 << arg8 << arg9
               << arg0 << arg1 << arg2 << arg3 << arg4 << arg5 << arg6 << arg7 << arg8 << arg9;

#ifdef FASTFORMAT_USE_WIDE_STRINGS
            std::wstring        s   =   ss.str();
#else /* ? FASTFORMAT_USE_WIDE_STRINGS */
            std::string         s   =   ss.str();
#endif /* FASTFORMAT_USE_WIDE_STRINGS */

#ifdef SHOW_FIRST_RESULT
(0 == i) && fprintf(stderr, "%.*s\n", int(s.size()), s.c_str());
#endif

            length += s.size();
        }}
        counter.stop();

        tm_IOStreams = counter.get_microseconds();

        if( verbosity >= 3 &&
            j == WARMUPS - 1)
        {
            ::fprintf(stdout, "IOStreams:  %lu\t(%lu)\n", (unsigned long)tm_IOStreams, (unsigned long)length);
        }
    }}


#ifdef FASTFORMAT_PERFTEST_USE_BOOST
    // Boost.Format

    { for(unsigned j = 0; j < WARMUPS; ++j)
    {
        length = 0;
        counter.start();
        { for(unsigned i = 0; i < ITERATIONS; ++i)
        {
            std::string s = boost::str(boost::format("%1%%2%%3%%4%%5%%6%%7%%8%%9%%10%%1%%2%%3%%4%%5%%6%%7%%8%%9%%10%") % arg0 % arg1 % arg2 % arg3 % arg4 % arg5 % arg6 % arg7 % arg8 % arg9);

#ifdef SHOW_FIRST_RESULT
(0 == i) && fprintf(stderr, "%.*s\n", int(s.size()), s.c_str());
#endif

            length += s.size();
        }}
        counter.stop();

        tm_Boost = counter.get_microseconds();

        if( verbosity >= 3 &&
            j == WARMUPS - 1)
        {
            ::fprintf(stdout, "Boost.Format: %lu\t(%lu)\n", (unsigned long)tm_Boost, (unsigned long)length);
        }
    }}
#endif /* FASTFORMAT_PERFTEST_USE_BOOST */


#ifdef FASTFORMAT_PERFTEST_USE_LOKI
    // Loki.SafeFormat

    { for(unsigned j = 0; j < WARMUPS; ++j)
    {
        length = 0;
        counter.start();
        { for(unsigned i = 0; i < ITERATIONS; ++i)
        {
            std::string s;

            Loki::SPrintf(s, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")(arg0)(arg1)(arg2.c_str())(arg3)(arg4.c_str())(arg5)(arg6)(arg7.c_str())(arg8)(arg9.c_str())(arg0)(arg1)(arg2.c_str())(arg3)(arg4.c_str())(arg5)(arg6)(arg7.c_str())(arg8)(arg9.c_str());

#ifdef SHOW_FIRST_RESULT
(0 == i) && fprintf(stderr, "%.*s\n", int(s.size()), s.c_str());
#endif

            length += s.size();
        }}
        counter.stop();

        tm_Loki = counter.get_microseconds();

        if( verbosity >= 3 &&
            j == WARMUPS - 1)
        {
            ::fprintf(stdout, "Loki.SafeFormat: %lu\t(%lu)\n", (unsigned long)tm_Loki, (unsigned long)length);
        }
    }}
#endif /* FASTFORMAT_PERFTEST_USE_LOKI */


#ifdef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING
    // CString::Format()

    { for(unsigned j = 0; j < WARMUPS; ++j)
    {
        length = 0;
        counter.start();
        { for(unsigned i = 0; i < ITERATIONS; ++i)
        {
            CString s;

            s.Format(TX("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")
                        ,   arg0.c_str(), arg1, arg2.c_str(), arg3.c_str(), arg4.c_str(), arg5.c_str(), arg6, arg7.c_str(), arg8.c_str(), arg9.c_str()
                        ,   arg0.c_str(), arg1, arg2.c_str(), arg3.c_str(), arg4.c_str(), arg5.c_str(), arg6, arg7.c_str(), arg8.c_str(), arg9.c_str());

#ifdef SHOW_FIRST_RESULT
(0 == i) && fprintf(stderr, "%.*s\n", int(s.GetLength()), static_cast<char const*>(s));
#endif

            length += size_t(s.GetLength());
        }}
        counter.stop();

        tm_CString_Format = counter.get_microseconds();

        if( verbosity >= 3 &&
            j == WARMUPS - 1)
        {
            ::fprintf(stdout, "CString::Format(): %lu\t(%lu)\n", (unsigned long)tm_CString_Format, (unsigned long)length);
        }
    }}


#endif /* FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING */
    // sprintf()

    { for(unsigned j = 0; j < WARMUPS; ++j)
    {
        length = 0;
        counter.start();
        { for(unsigned i = 0; i < ITERATIONS; ++i)
        {
            char    sz[10001];
            int     cch = ::sprintf(&sz[0], TX("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s")
                        ,   arg0.c_str(), arg1, arg2.c_str(), arg3.c_str(), arg4.c_str(), arg5.c_str(), arg6, arg7.c_str(), arg8.c_str(), arg9.c_str()
                        ,   arg0.c_str(), arg1, arg2.c_str(), arg3.c_str(), arg4.c_str(), arg5.c_str(), arg6, arg7.c_str(), arg8.c_str(), arg9.c_str());

            std::string s(sz, size_t(cch));

#ifdef SHOW_FIRST_RESULT
(0 == i) && fprintf(stderr, "%.*s\n", int(s.size()), s.c_str());
#endif

            length += s.size();
        }}
        counter.stop();

        tm_Streams = counter.get_microseconds();

        if( verbosity >= 3 &&
            j == WARMUPS - 1)
        {
            ::fprintf(stdout, "sprintf():  %lu\t(%lu)\n", (unsigned long)tm_Streams, (unsigned long)length);
        }
    }}


    // FastFormat.Format

    { for(unsigned j = 0; j < WARMUPS; ++j)
    {
        length = 0;
        counter.start();
        { for(unsigned i = 0; i < ITERATIONS; ++i)
        {
#ifdef FASTFORMAT_USE_WIDE_STRINGS
            std::wstring    s;
#else /* ? FASTFORMAT_USE_WIDE_STRINGS */
            std::string     s;
#endif /* FASTFORMAT_USE_WIDE_STRINGS */

            fastformat::fmt(s, TX("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}")
                        ,   arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);

#ifdef SHOW_FIRST_RESULT
(0 == i) && fprintf(stderr, "%.*s\n", int(s.size()), s.c_str());
#endif

            length += s.size();
        }}
        counter.stop();

        tm_FF_Format = counter.get_microseconds();

        if( verbosity >= 3 &&
            j == WARMUPS - 1)
        {
            ::fprintf(stdout, "FastFormat.Format: %lu\t(%lu)\n", (unsigned long)tm_FF_Format, (unsigned long)length);
        }
    }}


    // FastFormat.Write

    { for(unsigned j = 0; j < WARMUPS; ++j)
    {
        length = 0;
        counter.start();
        { for(unsigned i = 0; i < ITERATIONS; ++i)
        {
#ifdef FASTFORMAT_USE_WIDE_STRINGS
            std::wstring    s;
#else /* ? FASTFORMAT_USE_WIDE_STRINGS */
            std::string     s;
#endif /* FASTFORMAT_USE_WIDE_STRINGS */

            fastformat::write(s, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);

#ifdef SHOW_FIRST_RESULT
(0 == i) && fprintf(stderr, "%.*s\n", int(s.size()), s.c_str());
#endif

            length += s.size();
        }}
        counter.stop();

        tm_FF_Write = counter.get_microseconds();

        if( verbosity >= 3 &&
            j == WARMUPS - 1)
        {
            ::fprintf(stdout, "FastFormat.Write: %lu\t(%lu)\n", (unsigned long)tm_FF_Write, (unsigned long)length);
        }
    }}

    STLSOFT_SUPPRESS_UNUSED(length);

    std::string     fmt1;
    std::string     fmt2;

    fastformat::ignore_unreferenced_arguments_scope scoper;

    switch(verbosity)
    {
        case    0:
            // no output
            break;
        case    1:
            fmt1 = "";
            fmt1 += "S:FF.F:\t{0}";
            fmt1 += "\tIOS:FF.F:\t{1}";
            fmt1 += "\tFF.W:FF.F:\t{3}";
#ifdef FASTFORMAT_PERFTEST_USE_BOOST
            fmt1 += "\tB.F:FF.F:\t{4}";
#endif /* FASTFORMAT_PERFTEST_USE_BOOST */
#ifdef FASTFORMAT_PERFTEST_USE_LOKI
            fmt1 += "\tL.SF:FF.F:\t{5}";
#endif /* FASTFORMAT_PERFTEST_USE_LOKI */
#ifdef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING
            fmt1 += "\tMFC.F:FF.F:\t{2}";
#endif /* FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING */
            fastformat::fmtln(  std::cout, fmt1
                            ,   double(tm_Streams) / double(tm_FF_Format)
                            ,   double(tm_IOStreams) / double(tm_FF_Format)
                            ,   double(tm_CString_Format) / double(tm_FF_Format)
                            ,   double(tm_FF_Write) / double(tm_FF_Format)
                            ,   double(tm_Boost) / double(tm_FF_Format)
                            ,   double(tm_Loki) / double(tm_FF_Format));
            fmt1 = "";
            fmt1 += "S:FF.W:\t{0}";
            fmt1 += "\tIOS:FF.W:\t{1}";
            fmt1 += "\tFF.F:FF.W:\t{2}";
#ifdef FASTFORMAT_PERFTEST_USE_BOOST
            fmt1 += "\tB.F:FF.W:\t{3}";
#endif /* FASTFORMAT_PERFTEST_USE_BOOST */
#ifdef FASTFORMAT_PERFTEST_USE_LOKI
            fmt1 += "\tL.SF:FF.W:\t{3}";
#endif /* FASTFORMAT_PERFTEST_USE_LOKI */
#ifdef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING
            fmt1 += "\tMFC.F:FF.W:\t{4}";
#endif /* FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING */
            fastformat::fmtln(  std::cout, fmt1
                            ,   double(tm_Streams) / double(tm_FF_Write)
                            ,   double(tm_IOStreams) / double(tm_FF_Write)
                            ,   double(tm_CString_Format) / double(tm_FF_Write)
                            ,   double(tm_FF_Format) / double(tm_FF_Write)
                            ,   double(tm_Boost) / double(tm_FF_Write)
                            ,   double(tm_Loki) / double(tm_FF_Write));
            break;
        case    2:
            fastformat::fmtln(std::cout, "{0}\tFastFormat.Format\tFastFormat.Write", TestId);
            fastformat::fmtln(std::cout, "Streams\t{0}\t{1}", double(tm_Streams) / double(tm_FF_Format), double(tm_Streams) / double(tm_FF_Write));
            fastformat::fmtln(std::cout, "IOStreams\t{0}\t{1}", double(tm_IOStreams) / double(tm_FF_Format), double(tm_IOStreams) / double(tm_FF_Write));
#ifdef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING
            fastformat::fmtln(std::cout, "CString::Format\t{0}\t{1}", double(tm_CString_Format) / double(tm_FF_Format), double(tm_CString_Format) / double(tm_FF_Write));
#else /* ? FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING */
            fastformat::writeln(std::cout, "");
#endif /* FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING */
#ifdef FASTFORMAT_PERFTEST_USE_BOOST
            fastformat::fmtln(std::cout, "Boost.Format\t{0}\t{1}", double(tm_Boost) / double(tm_FF_Format), double(tm_Boost) / double(tm_FF_Write));
#else /* ? FASTFORMAT_PERFTEST_USE_BOOST */
            fastformat::writeln(std::cout, "");
#endif /* FASTFORMAT_PERFTEST_USE_BOOST */
#ifdef FASTFORMAT_PERFTEST_USE_LOKI
            fastformat::fmtln(std::cout, "Loki.SafeFormat\t{0}\t{1}", double(tm_Loki) / double(tm_FF_Format), double(tm_Loki) / double(tm_FF_Write));
#else /* ? FASTFORMAT_PERFTEST_USE_LOKI */
            fastformat::writeln(std::cout, "");
#endif /* FASTFORMAT_PERFTEST_USE_LOKI */
            fastformat::fmtln(std::cout, "FastFormat.Format\t{0}\t{1}", "", double(tm_FF_Format) / double(tm_FF_Write));
            fastformat::fmtln(std::cout, "FastFormat.Write\t{0}\t{1}", double(tm_FF_Write) / double(tm_FF_Format), "");
            break;
        case    3:
            ::puts("");
            ::fprintf(stdout, "sprintf():FastFormat.Format:         \t%2.04g\n", double(tm_Streams) / double(tm_FF_Format));
            ::fprintf(stdout, "IOStreams:FastFormat.Format:         \t%2.04g\n", double(tm_IOStreams) / double(tm_FF_Format));
#ifdef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING
            ::fprintf(stdout, "CString::Format():FastFormat.Format: \t%2.04g\n", double(tm_CString_Format) / double(tm_FF_Format));
#endif /* FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING */
#ifdef FASTFORMAT_PERFTEST_USE_BOOST
            ::fprintf(stdout, "Boost.Format:FastFormat.Format:      \t%2.04g\n", double(tm_Boost) / double(tm_FF_Format));
#endif /* FASTFORMAT_PERFTEST_USE_BOOST */
#ifdef FASTFORMAT_PERFTEST_USE_LOKI
            ::fprintf(stdout, "Loki.SafeFormat:FastFormat.Format:   \t%2.04g\n", double(tm_Loki) / double(tm_FF_Format));
#endif /* FASTFORMAT_PERFTEST_USE_LOKI */
            ::puts("");
            ::fprintf(stdout, "sprintf():FastFormat.Write:          \t%2.04g\n", double(tm_Streams) / double(tm_FF_Write));
            ::fprintf(stdout, "IOStreams:FastFormat.Write:          \t%2.04g\n", double(tm_IOStreams) / double(tm_FF_Write));
#ifdef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING
            ::fprintf(stdout, "CString::Format():FastFormat.Write:  \t%2.04g\n", double(tm_CString_Format) / double(tm_FF_Write));
#endif /* FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_CSTRING */
#ifdef FASTFORMAT_PERFTEST_USE_BOOST
            ::fprintf(stdout, "Boost.Format:FastFormat.Write:       \t%2.04g\n", double(tm_Boost) / double(tm_FF_Write));
#endif /* FASTFORMAT_PERFTEST_USE_BOOST */
#ifdef FASTFORMAT_PERFTEST_USE_LOKI
            ::fprintf(stdout, "Loki.SafeFormat:FastFormat.Write:    \t%2.04g\n", double(tm_Loki) / double(tm_FF_Write));
#endif /* FASTFORMAT_PERFTEST_USE_LOKI */
            ::fprintf(stdout, "\n");
            ::fprintf(stdout, "FastFormat.Format:FastFormat.Write:  \t%2.04g\n", double(tm_FF_Format) / double(tm_FF_Write));
            break;
    }

    return EXIT_SUCCESS;
}
Example #12
0
int main(int argc, char* argv[]) {
  
  if(argc != 4) {
    std::cout << "SDFGen - A utility for converting closed oriented triangle meshes into grid-based signed distance fields.\n";
    std::cout << "\nThe output file format is:";
    std::cout << "<ni> <nj> <nk>\n";
    std::cout << "<origin_x> <origin_y> <origin_z>\n";
    std::cout << "<dx>\n";
    std::cout << "<value_1> <value_2> <value_3> [...]\n\n";
    
    std::cout << "(ni,nj,nk) are the integer dimensions of the resulting distance field.\n";
    std::cout << "(origin_x,origin_y,origin_z) is the 3D position of the grid origin.\n";
    std::cout << "<dx> is the grid spacing.\n\n";
    std::cout << "<value_n> are the signed distance data values, in ascending order of i, then j, then k.\n";

    std::cout << "The output filename will match that of the input, with the OBJ suffix replaced with SDF.\n\n";

    std::cout << "Usage: SDFGen <filename> <dx> <padding>\n\n";
    std::cout << "Where:\n";
    std::cout << "\t<filename> specifies a Wavefront OBJ (text) file representing a *triangle* mesh (no quad or poly meshes allowed). File must use the suffix \".obj\".\n";
    std::cout << "\t<dx> specifies the length of grid cell in the resulting distance field.\n";
    std::cout << "\t<padding> specifies the number of cells worth of padding between the object bound box and the boundary of the distance field grid. Minimum is 1.\n\n";
    
    exit(-1);
  }

  std::string filename(argv[1]);
  if(filename.size() < 5 || filename.substr(filename.size()-4) != std::string(".obj")) {
    std::cerr << "Error: Expected OBJ file with filename of the form <name>.obj.\n";
    exit(-1);
  }

  std::stringstream arg2(argv[2]);
  float dx;
  arg2 >> dx;
  
  std::stringstream arg3(argv[3]);
  int padding;
  arg3 >> padding;

  if(padding < 1) padding = 1;
  //start with a massive inside out bound box.
  Vec3f min_box(std::numeric_limits<float>::max(),std::numeric_limits<float>::max(),std::numeric_limits<float>::max()), 
    max_box(-std::numeric_limits<float>::max(),-std::numeric_limits<float>::max(),-std::numeric_limits<float>::max());
  
  std::cout << "Reading data.\n";

  std::ifstream infile(argv[1]);
  if(!infile) {
    std::cerr << "Failed to open. Terminating.\n";
    exit(-1);
  }

  int ignored_lines = 0;
  std::string line;
  std::vector<Vec3f> vertList;
  std::vector<Vec3ui> faceList;
  while(!infile.eof()) {
    std::getline(infile, line);

    //.obj files sometimes contain vertex normals indicated by "vn"
    if(line.substr(0,1) == std::string("v") && line.substr(0,2) != std::string("vn")){
      std::stringstream data(line);
      char c;
      Vec3f point;
      data >> c >> point[0] >> point[1] >> point[2];
      vertList.push_back(point);
      update_minmax(point, min_box, max_box);
    }
    else if(line.substr(0,1) == std::string("f")) {