コード例 #1
0
ファイル: simplemap.cpp プロジェクト: AndreaCensi/csm
	bool Environment::ray_tracing(const double p[2], const double direction,  double& out_distance, double &out_alpha, int*stuff_id) const {
	
		int champion = -1;
		double champion_range, champion_alpha;
		for(size_t i=0;i<stuff.size();i++) {
			Stuff * s = stuff.at(i);
			
			double range, alpha;
			if(s->ray_tracing(p,direction,range,alpha)){
				if(champion==-1 || range<champion_range) {
					champion = i;
					champion_range = range;
					champion_alpha = alpha;
				}
			}
			
		}
		
		if(champion != -1) {
			*stuff_id = champion;
			out_distance = champion_range;
			out_alpha = champion_alpha;
		
			return true;
		} else {
			return false;
		}
	}
コード例 #2
0
ファイル: ex03_stl.cpp プロジェクト: Strongc/study_example
int main()
{
  cereal::JSONOutputArchive output(std::cout); // stream to cout

  Stuff myStuff;
  myStuff.fillData();

  output( cereal::make_nvp("best data ever", myStuff) );
}
コード例 #3
0
ファイル: main.cpp プロジェクト: akosgarai/grafika
 //put a new stuff to the bag or rase the amount if the stuff isn't new
 void addStuff(Stuff s) {
     if(stuffNum < bagcapacity) {
         for(int i = 0; i < stuffNum; i++) {
             if(this->myStuffs[i].getName() == s.getName()) {
                 this->myStuffs[i].add(s.getAmount());
                 return;
             }
         }
         myStuffs[stuffNum] = s;
         stuffNum++;
         cout << "Your found your " << stuffNum <<". stuff: " << this->myStuffs[stuffNum-1].getName() << "\n";
     } else {
         cout << "Sorry, but you are full. You should drop something.\n";
     }
 }
コード例 #4
0
ファイル: sandbox_json.cpp プロジェクト: JoyIfBam5/cereal
// ######################################################################
int main()
{
  std::cout << std::boolalpha << std::endl;

  {
    std::ofstream os("file.json");
    cereal::JSONOutputArchive oar( os );

    //auto f = std::make_shared<Fixture>();
    //auto f2 = f;
    //oar( f );
    //oar( f2 );
    Stuff s; s.fillData();
    oar( cereal::make_nvp("best data ever", s) );
  }

  {
    std::ifstream is("file.json");
    std::string str((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>());
    std::cout << "---------------------" << std::endl << str << std::endl << "---------------------" << std::endl;
  }

  // playground
  {
    cereal::JSONOutputArchive archive( std::cout );
    bool arr[] = {true, false};
    std::vector<int> vec = {1, 2, 3, 4, 5};
    archive( CEREAL_NVP(vec),
        arr );
    auto f = std::make_shared<Fixture>();
    auto f2 = f;
    archive( f );
    archive( f2 );
  }

  // test out of order
  std::stringstream oos;
  {
    cereal::JSONOutputArchive ar(oos);
    cereal::JSONOutputArchive ar2(std::cout,
        cereal::JSONOutputArchive::Options(2, cereal::JSONOutputArchive::Options::IndentChar::space, 2) );

    ar( cereal::make_nvp( "1", 1 ),
        cereal::make_nvp( "2", 2 ),
        3,
        0, // unused
        cereal::make_nvp( "4", 4 ),
        cereal::make_nvp( "5", 5 ) );

    int x = 33;
    ar.saveBinaryValue( &x, sizeof(int), "bla" );

    ar2( cereal::make_nvp( "1", 1 ),
         cereal::make_nvp( "2", 2 ),
         3,
         0, // unused
         cereal::make_nvp( "4", 4 ),
         cereal::make_nvp( "5", 5 ) );
    ar2.saveBinaryValue( &x, sizeof(int), "bla" );

    OOJson oo( 1, 2, true, 4.2 );
    ar( CEREAL_NVP(oo) );
    ar2( CEREAL_NVP(oo) );

    // boost stuff
    ar & cereal::make_nvp("usingop&", oo ) & 6;
    ar << 5 << 4 << 3;

    ar2 & cereal::make_nvp("usingop&", oo ) & 6;
    ar2 << 5 << 4 << 3;

    long double ld = std::numeric_limits<long double>::max();
    long long ll = std::numeric_limits<long long>::max();
    unsigned long long ull = std::numeric_limits<unsigned long long>::max();

    ar( CEREAL_NVP(ld),
        CEREAL_NVP(ll),
        CEREAL_NVP(ull) );

    ar2( CEREAL_NVP(ld),
         CEREAL_NVP(ll),
         CEREAL_NVP(ull) );
  }

  {
    cereal::JSONInputArchive ar(oos);
    int i1, i2, i3, i4, i5, x;

    ar( i1 );
    ar( cereal::make_nvp( "2", i2 ), i3 );

    ar( cereal::make_nvp( "4", i4 ),
        i5 );

    ar.loadBinaryValue( &x, sizeof(int) );

    OOJson ii;
    ar( cereal::make_nvp("oo", ii) );
    ar( cereal::make_nvp( "2", i2 ) );

    std::cout << i1 << " " << i2 << " " << i3 << " " << i4 << " " << i5 << std::endl;
    std::cout << x << std::endl;
    std::cout << ii.a << " " << ii.b << " " << ii.c.first << " " << ii.c.second << " ";
    for( auto z : ii.d )
      std::cout << z << " ";
    std::cout << std::endl;

    OOJson oo;
    ar >> cereal::make_nvp("usingop&", oo );
    std::cout << oo.a << " " << oo.b << " " << oo.c.first << " " << oo.c.second << " ";
    for( auto z : oo.d )
      std::cout << z << " ";

    int aa, a, b, c;
    ar & aa & a & b & c;
    std::cout << aa << " " << a << " " << b << " " << c << std::endl;

    long double ld;
    long long ll;
    unsigned long long ull;

    ar( CEREAL_NVP(ld),
        CEREAL_NVP(ll),
        CEREAL_NVP(ull) );

    std::cout << (ld  == std::numeric_limits<long double>::max()) << std::endl;
    std::cout << (ll  == std::numeric_limits<long long>::max()) << std::endl;
    std::cout << (ull == std::numeric_limits<unsigned long long>::max()) << std::endl;
  }

  return 0;
}