TEST(GenericType, instance_in_instance) {
	::testing::FLAGS_gtest_death_test_style = "threadsafe";

	std::vector<TypeBase::ParameterPair> param_vec1, param_vec2;
	param_vec1.push_back( std::make_pair("param", boost::make_shared<Double>()) );
	param_vec2.push_back( std::make_pair("param", boost::make_shared<String>()) );

	static Parameter param = Parameter("param");
	static Instance inst_in = Instance(param, param_vec2).close();

	static Record in_rec = Record("Inner record", "")
			.root_of_generic_subtree()
			.declare_key("key1", inst_in, "Inner instance.")
			.declare_key("param", Parameter("param"), "Parameterized key")
			.close();

	static Instance inst = Instance(in_rec, param_vec1).close();

	static Record root_rec = Record("Root record", "")
			.declare_key("rec", inst, "First instance.")
			.declare_key("some_int", Integer(), "Int key")
			.close();

	TypeBase::lazy_finish();

	Record::KeyIter key_it = root_rec.begin();
	EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Record) );
	const Record *inner_rec = static_cast<const Record *>(key_it->type_.get());
	EXPECT_EQ(inner_rec->size(), 2);
	Record::KeyIter key_it_in = inner_rec->begin();
	EXPECT_EQ( typeid( *(key_it_in->type_.get()) ), typeid(String) );
	++key_it_in;
	EXPECT_EQ( typeid( *(key_it_in->type_.get()) ), typeid(Double) );
}
Beispiel #2
0
void Table::addEntry(Record& new_record)
{
	vector<field>::iterator iter_record = new_record.begin();

	string *fields = new string("(");
	string *values= new string("(");

	bool start = true;;

	while( iter_record != new_record.end() ){
		if (!start){
			fields->append(",");
			values->append(",");
		}
		fields->append(iter_record->label);
		iter_record->getString(values);

		std::cout << "label: " << iter_record->label << ",data; " ; iter_record->print();
		iter_record++;
		start = false;
	}

	fields->append(")");
	values->append(")");

	stringstream queryStream;
	queryStream << "INSERT INTO " << this->_name << " " << *fields << " VALUES " << *values << ";";

	delete fields;
	delete values;

	this->execute( this->conn, queryStream.str());
}
TEST(GenericType, record_with_record) {
	::testing::FLAGS_gtest_death_test_style = "threadsafe";
	static Record problem = Record("problem", "desc.")
			.declare_key("primary", get_record_with_record(&get_colors_selection(), boost::make_shared<Integer>(0,100)), "Primary problem.")
			.declare_key("secondary", get_record_with_record(&get_shapes_selection(), boost::make_shared<Double>()), "Secondary problem.")
			.declare_key("bool", Bool(), "Some bool key.")
			.close();

	TypeBase::lazy_finish();

	Record::KeyIter key_it = problem.begin();
	{
		EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Record) );
		const Record *in_rec = static_cast<const Record *>(key_it->type_.get());
		in_rec->write_attributes(cout); cout << endl;
		Record::KeyIter in_rec_it = in_rec->begin();
		EXPECT_EQ( typeid( *(in_rec_it->type_.get()) ), typeid(Record) );
		const Record *in_in_rec = static_cast<const Record *>(in_rec_it->type_.get());
		EXPECT_EQ( typeid( *(in_in_rec->begin()->type_.get()) ), typeid(Integer) );
	}
	++key_it;
	{
		EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Record) );
		const Record *in_rec = static_cast<const Record *>(key_it->type_.get());
		in_rec->write_attributes(cout); cout << endl;
		Record::KeyIter in_rec_it = in_rec->begin();
		EXPECT_EQ( typeid( *(in_rec_it->type_.get()) ), typeid(Record) );
		const Record *in_in_rec = static_cast<const Record *>(in_rec_it->type_.get());
		EXPECT_EQ( typeid( *(in_in_rec->begin()->type_.get()) ), typeid(Double) );
	}
}
Beispiel #4
0
Boolean IMDB::SetRecord(const String &strRecordName,
                        const Record &recSrc,
                        Boolean bCreate,
                        Boolean bAll)
{
  MapStrRec::iterator iter = m_mpRecords.find(strRecordName);
  if(iter == m_mpRecords.end())
    {
      if(!bCreate) 
      {
      	return FALSE;
      }
      m_mpRecords[strRecordName] = recSrc.Map();			// !!! not right
    }
  else
    {
      MapStringToField &mpDest = iter->second;

      if(bAll)
        {
          Record::const_iterator it = recSrc.begin();
          while(it != recSrc.end()) { mpDest.insert(*it); it++; }
        }
      else
        {
          SetOfStrings::const_iterator itDirty;
          itDirty = recSrc.GetFirstDirty();
          while(itDirty != recSrc.GetLastDirty())
            {
              String str = *itDirty;
              Record::const_iterator itSrcField = recSrc.find(*itDirty);
              if(itSrcField != recSrc.end())
              {
                  mpDest.insert(*itSrcField);
              }
              else
                {
                  MapStringToField::iterator it =
                    mpDest.find(*itDirty);
                  mpDest.erase(it);
                }
              ++itDirty;
            }
        }
    }

  return TRUE;
}
void DumpD3DResourceReleaseResults()
{
	Record::const_iterator ri = record.begin();

	//INFO_MSG( "Dumping D3D resource release results...\n\n" );
	//INFO_MSG( "Resource, Total time, Total calls\n" );

	while ( ri != record.end() )
	{
		double seconds = double(ri->second.first)/double( stampsPerSecond() );

		//INFO_MSG("%s, %f, %d\n",
		//	ri->first.c_str(), seconds, ri->second.second );
		ri++;
	}
}
TEST(GenericType, generic_abstract) {
	::testing::FLAGS_gtest_death_test_style = "threadsafe";
	static Record desc1 = Record("Descendant1", "")
			.derive_from(get_abstract_type())
			.declare_key("param", Parameter("param"), "desc.")
			.declare_key("some_int", Integer(), "Integer key")
			.close();

	static Record desc2 = Record("Descendant2", "")
			.derive_from(get_abstract_type())
			.declare_key("param", Parameter("param"), "desc.")
			.declare_key("some_double", Double(), "Double key")
			.close();

	static Record rec_with_abstracts = Record("rec_of_arr", "desc.")
			.declare_key("abstract1", get_generic_abstract(&get_colors_selection()), "Primary problem.")
			.declare_key("abstract2", get_generic_abstract(&get_shapes_selection()), "Secondary problem.")
			.declare_key("bool", Bool(), "Some bool key.")
			.close();

	TypeBase::lazy_finish();

	Record::KeyIter key_it = rec_with_abstracts.begin();
	{
		EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Abstract) );
		const Abstract *abstract = static_cast<const Abstract *>(key_it->type_.get());
		EXPECT_EQ( abstract->child_size(), 2 );
		Record::KeyIter desc_it = abstract->get_descendant("Descendant1").begin();
		EXPECT_EQ( typeid( *(desc_it->type_.get()) ), typeid(String) );
		++desc_it;
		const Selection *sel = static_cast<const Selection *>(desc_it->type_.get());
		EXPECT_EQ( sel->type_name(), "colors" );
	}

	++key_it;
	{
		EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Abstract) );
		const Abstract *abstract = static_cast<const Abstract *>(key_it->type_.get());
		EXPECT_EQ( abstract->child_size(), 2 );
		Record::KeyIter desc_it = abstract->get_descendant("Descendant1").begin();
		EXPECT_EQ( typeid( *(desc_it->type_.get()) ), typeid(String) );
		++desc_it;
		const Selection *sel = static_cast<const Selection *>(desc_it->type_.get());
		EXPECT_EQ( sel->type_name(), "shapes" );
	}
}
TEST(GenericType, generic_array) {
	::testing::FLAGS_gtest_death_test_style = "threadsafe";
	static Record arr_rec = Record("rec_of_arr", "desc.")
			.declare_key("array1", get_generic_array(&get_colors_selection()), "Primary problem.")
			.declare_key("array2", get_generic_array(&get_shapes_selection()), "Secondary problem.")
			.close();

	TypeBase::lazy_finish();

	Record::KeyIter key_it = arr_rec.begin();
	EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Array) );
	const Array *array = static_cast<const Array *>(key_it->type_.get());
	EXPECT_EQ( typeid( array->get_sub_type() ), typeid(Selection) );

	++key_it;
	EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Array) );
}
TEST(GenericType, generic_record) {
	::testing::FLAGS_gtest_death_test_style = "threadsafe";
	static Record problem = Record("problem", "desc.")
			.declare_key("primary", get_generic_record(&get_colors_selection(), 10), "Primary problem.")
			.declare_key("secondary", get_generic_record(&get_shapes_selection(), 1000), "Secondary problem.")
			.declare_key("bool", Bool(), "Some bool key.")
			.close();

	TypeBase::lazy_finish();

	Record::KeyIter key_it = problem.begin();
	EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Record) );
	const Record *in_rec = static_cast<const Record *>(key_it->type_.get());
	EXPECT_EQ( typeid( *(in_rec->begin()->type_.get()) ), typeid(Selection) );

	++key_it;
	EXPECT_EQ( typeid( *(key_it->type_.get()) ), typeid(Record) );
}
Beispiel #9
0
	bool BookManager::importFile(
			const char* path, int threshold) {
		// 棋譜の読み込み
		Record record;
		if (!CsaReader::read(path, record)) {
			return false;
		}
		// 初手から順に棋譜を見ていく。
		record.begin();
		while (threshold == IMPORT_UNLIMITED ||
				record.getCurrent() < threshold) {
			Move move;
			if (!record.getNextMove(move)) {
				break;
			}
			book.addMove(record.getPosition().getHash(), move);
			record.next();
		}
		return true;
	}