Example #1
0
void CheckRawValue()
{
	typedef Tuple2<int, int> T;
	T x = MakeTuple(11, 22);
	Value v = RawToValue(x);
	const T& x2 = v.To<T>();
	ASSERT(x2 == x);
}
TEST(TupleTest, Basic)
{
    Tuple1<int> t1(1);
    Tuple2<int, const char*> t2 = MakeTuple(1, static_cast<const char*>("wee"));
    Tuple3<int, int, int> t3(1, 2, 3);
    Tuple4<int, int, int, int*> t4(1, 2, 3, &t1.a);
    Tuple5<int, int, int, int, int*> t5(1, 2, 3, 4, &t4.a);
    Tuple6<int, int, int, int, int, int*> t6(1, 2, 3, 4, 5, &t4.a);

    EXPECT_EQ(1, t1.a);
    EXPECT_EQ(1, t2.a);
    EXPECT_EQ(1, t3.a);
    EXPECT_EQ(2, t3.b);
    EXPECT_EQ(3, t3.c);
    EXPECT_EQ(1, t4.a);
    EXPECT_EQ(2, t4.b);
    EXPECT_EQ(3, t4.c);
    EXPECT_EQ(1, t5.a);
    EXPECT_EQ(2, t5.b);
    EXPECT_EQ(3, t5.c);
    EXPECT_EQ(4, t5.d);
    EXPECT_EQ(1, t6.a);
    EXPECT_EQ(2, t6.b);
    EXPECT_EQ(3, t6.c);
    EXPECT_EQ(4, t6.d);
    EXPECT_EQ(5, t6.e);

    EXPECT_EQ(1, t1.a);
    DispatchToFunction(&DoAdd, t4);
    EXPECT_EQ(6, t1.a);

    int res = 0;
    DispatchToFunction(&DoAdd, MakeTuple(9, 8, 7, &res));
    EXPECT_EQ(24, res);

    Addy addy;
    EXPECT_EQ(1, t4.a);
    DispatchToMethod(&addy, &Addy::DoAdd, t5);
    EXPECT_EQ(10, t4.a);

    Addz addz;
    EXPECT_EQ(10, t4.a);
    DispatchToMethod(&addz, &Addz::DoAdd, t6);
    EXPECT_EQ(15, t4.a);
}
Example #3
0
void sOptimizedTextRenderer::DrawChar(int x, int _y, int chr, int width, Font font, Color color)
{
	LTIMING("DrawChar");
	if(y != _y) {
		Flush();
		y = _y;
	}
	Chrs *c;
	{
		LTIMING("Map");
		c = &cache.GetAdd(MakeTuple(font, color));
	}
	if(c->x.GetCount() && c->x.Top() > x) {
		Flush();
		c = &cache.GetAdd(MakeTuple(font, color));
	}
	c->text.Cat(chr);
	c->x.Add(x);
}
Example #4
0
    virtual void GetEdgeDofNrs ( int nr, Array<int> & dnums ) const
    {
      dnums.SetSize0();
      if (ma->GetDimension() == 3) return;

      /*
      dnums += nr;
      dnums += GetFacetDofs(nr);
      */
      dnums = MakeTuple (nr, GetFacetDofs(nr));
    }
Example #5
0
void GetAllMacros(Md5Stream& md5, const String& id, Index<int>& segment_id)
{
	Vector< Tuple2<int, int> > pos;
	Vector<const CppMacro *> def;
	String r;
	int q = sAllMacros.Find(id);
	while(q >= 0) {
		const PPMacro& m = sAllMacros[q];
		int si = segment_id.Find(m.segment_id);
		if(si >= 0) {
			pos.Add(MakeTuple(si, m.line));
			def.Add(&m.macro);
		}
		q = sAllMacros.FindNext(q);
	}
	IndexSort(pos, def);
	int n = def.GetCount();
	if(n) {
		md5.Put(&n, sizeof(int));
		md5.Put(id);
		for(int i = 0; i < n; i++)
			md5.Put(def[i]->md5, 16);
	}
}
Example #6
0
	virtual Tuple2<Font, int>  Key() const        { return MakeTuple(font, angle); }
Example #7
0
mozilla::ipc::IPCResult
TestAsyncReturnsParent::RecvPong(PongResolver&& aResolve)
{
  aResolve(MakeTuple(sMagic1, sMagic2));
  return IPC_OK();
}
Example #8
0
void TupleTutorial()
{
	/// . Tuples

	/// Template class `Tuple` allows combining 2-4 values with
	/// different types. These are principally similar to `std::tuple`, with some advantages.
	/// Unlike `std::tuple`, individual elements are directly accessible as member variables
	/// `a`..`d`, `Tuple` supports persistent storage patterns (`Serialize`, `Jsonize`, `Xmlize`), hash
	/// code (`GetHashValue`), conversion to `String` and Value conversions.
	
	/// To create a `Tuple` value, you can use the `MakeTuple` function.

	Tuple<int, String, String> x = MakeTuple(12, "hello", "world");

	/// Individual values are accessible as members `a` .. `d`:

	DUMP(x.a);
	DUMP(x.b);
	DUMP(x.c);
	
	/// Or using `Get`:
	
	DUMP(x.Get<1>());
	DUMP(x.Get<int>());
	
	/// As long as all individual types have conversion to `String` (`AsString`), the tuple also
	/// has such conversion and thus can e.g. be easily logged:

	DUMP(x);

	/// As long as individual types have defined `GetHashValue`, so does `Tuple`:

	DUMP(GetHashValue(x));

	/// As long as individual types have defined `operator==`, `Tuple` has defined `operator==`
	/// and `operator!=`:

	Tuple<int, String, String> y = x;
	DUMP(x == y);
	DUMP(x != y);
	y.a++;
	DUMP(x == y);
	DUMP(x != y);

	/// As long as all individual types have defined `SgnCompare`,
	/// Tuple has SgnCompare, Compare method and operators <, <=, >, >=:

	DUMP(x.Compare(y));
	DUMP(SgnCompare(x, y));
	DUMP(x < y);
	
	/// GetCount returns the width of `Tuple`:
	
	DUMP(x.GetCount());
	
	/// Elements that are directly convertible with `Value` can be 'Get'/'Set':
	
	for(int i = 0; i < x.GetCount(); i++)
		DUMP(x.Get(i));
	
	///
	
	x.Set(1, "Hi");
	DUMP(x);
	
	/// As long as all individual types are convertible with `Value`, you can convert Tuple to
	/// `ValueArray` and back:
	
	ValueArray va = x.GetArray();
	DUMP(va);

	va.Set(2, "Joe");
	x.SetArray(va);
	
	/// It is OK to assign `Tuple` to `Tuple` with different individual types, as long as types
	/// are directly convertible:
	
	Tuple<double, String, String> d = x;
	DUMP(d);
	
	/// Tie can be used to assign tuple to l-values:
	
	int i;
	String s1, s2;
	
	Tie(i, s1, s2) = x;
	
	DUMP(i);
	DUMP(s1);
	DUMP(s2);

	/// U++ Tuples are carefully designed as POD type, which allows POD arrays to be intialized
	/// with classic C style:
	
	static Tuple2<int, const char *> map[] = {
		{ 1, "one" },
		{ 2, "one" },
		{ 3, "one" },
	};
	

	/// Simple FindTuple template function is provided to search for tuple based on the first
	/// value (`a`) (linear O(n) search):
	
	DUMP(FindTuple(map, __countof(map), 3)->b);
	
	///
}
Example #9
0
int main()
{
    base::AtExitManager exit_manager;
    base::CommandLine::Init(0, NULL);
    BaseInitLoggingImpl(L"debug.log", base::LOG_ONLY_TO_FILE,
        base::LOCK_LOG_FILE, base::DELETE_OLD_LOG_FILE);

    int loga = base::Log2Floor(1);

    base::Environment* e = base::Environment::Create();
    std::string sys_path;
    e->GetVar("path", &sys_path);

    base::CPU cpu;

    bool finite = base::IsFinite(1.01);

    base::FilePath path;
    std::vector<std::wstring> components;
    path.GetComponents(&components);
    path.Append(L"c:");
    path.Append(L"pWRD");
    path.Append(L"testDir");
    path.Append(L"\\wlw.txt");
    path.GetComponents(&components);
    bool absolute = path.IsAbsolute();

    base::FilePath path2(L"wlwtxt");
    path2.GetComponents(&components);
    absolute = path2.IsAbsolute();

    base::FilePath search_path(L"C:\\");
    base::CountFilesCreatedAfter(search_path, base::Time::Now());

    int err = base::EnsureDirectoryForFile(path, NULL);
    base::Delete(base::FilePath(L"c:\\pWRD"), true);

    FileVersionInfo* fvi = FileVersionInfo::CreateFileVersionInfoForCurrentModule();
    if(fvi)
    {
        std::wstring file_ver = fvi->file_version();
        delete fvi;
    }

    base::FileEnumerator file_iter(search_path, false,
        base::FileEnumerator::DIRECTORIES, L"3rd");
    for(base::FilePath current=file_iter.Next(); !current.Empty();
        current=file_iter.Next())
    {
        std::wcout << current.value() << std::endl;
        base::FileEnumerator::FindInfo fi;
        file_iter.GetFindInfo(&fi);
        if(file_iter.IsDirectory(fi))
        {
            int64 size = base::ComputeDirectorySize(current);
            std::wcout << L"Directory size is: " << size << std::endl;
            size = base::ComputeFilesSize(current, L"");
            std::wcout << L"Files size is: " << size << std::endl;
        }
    }

    Pickle p;
    p.WriteInt(1);
    p.WriteString("I'm wlw!");
    p.WriteWString(L"I'm WLW!");
    int p_i;
    std::string p_str;
    std::wstring p_wstr;
    void* iter = NULL;
    p.ReadInt(&iter, &p_i);
    p.ReadString(&iter, &p_str);
    p.ReadWString(&iter, &p_wstr);

    base::RegKey reg(HKEY_CURRENT_USER, L"Environment", KEY_QUERY_VALUE);
    std::wstring reg_temp;
    if(reg.Valid())
    {
        reg.ReadValue(L"TEMP", &reg_temp);
    }

    CoInitialize(NULL);
    base::ScopedComPtr<IDropTargetHelper, &IID_IDropTargetHelper> scomp;
    if(SUCCEEDED(scomp.CreateInstance(CLSID_DragDropHelper)))
    {
        scomp = NULL;
    }
    CoUninitialize();

    scoped_ptr<double> spd(new double(3.1));
    spd.reset();

    base::Singleton<FooClass>::get()->Bar();

    int cvt = 0;
    base::StringToInt("123", &cvt);
    std::string str_d = base::DoubleToString(2.123);

    base::StringPiece s1;
    assert(s1.length() == 0);
    assert(s1.size() == 0);
    assert(s1.data() == NULL);

    base::StringPiece s2("I love you");
    assert(s2.find('I') != base::StringPiece::npos);

    std::vector<std::string> v;
    base::SplitString("wlw&el", '&', &v);

    std::vector<std::string> subst;
    subst.push_back("10");
    subst.push_back("20");
    subst.push_back("30");
    std::string add = ReplaceStringPlaceholders("$2+$1=$3", subst, NULL);
    string16 bytes = FormatBytes(5*1024, DATA_UNITS_KIBIBYTE, true);

    std::string profile = base::StringPrintf("wlw's age is %d", 29);

    LOG(WARNING) << "This is a warning!";
    //DCHECK(1 == 0);

    base::Time::EnableHighResolutionTimer(true);
    base::Time t = base::Time::Now();
    base::Time::Exploded te;
    t.LocalExplode(&te);
    base::TimeTicks tt = base::TimeTicks::Now();
    base::TimeTicks tth = base::TimeTicks::HighResNow();

    std::string utf8 = WideToUTF8(L"wan lian wen - мРа╛нд");
    std::wstring wide = UTF8ToWide(utf8);

    DictionaryValue root;
    root.SetString("global.pages.homepage", "http://goateleporter.com");
    std::string homepage = "http://google.com";
    root.GetString("global.pages.homepage", &homepage);

    Version* ver = Version::GetVersionFromString("2.0.0.1");
    delete ver;

    base::WinVersion version = base::GetWinVersion();

    std::wstring user_sid;
    base::GetUserSidString(&user_sid);

    std::string base64;
    base::Base64Encode("I'm wlw.", &base64);
    std::string md5 = MD5String("I'm wlw.");
    std::string sha1 = base::SHA1HashString("I'm wlw.");
    std::string sha2 = base::SHA256HashString("I'm wlw.");

    std::string json = base::GetDoubleQuotedJson("a<>b;\nb = 0;");
    std::string json_write;
    base::JSONWriter::Write(&root, false, &json_write);
    Value* json_read = base::JSONReader::Read(json_write, false);
    delete json_read;

    Tuple3<int, double, bool> t3 = MakeTuple(10, 2.5, false);

    ObjClass obj;
    Callback0::Type* callback = NewCallback(&obj, &ObjClass::Bar);
    callback->Run();
    delete callback;

    thred.Start();
    thred.message_loop()->PostDelayedTask(new PrintTask(), 1000);

    MessageLoop msg_loop;
    msg_loop.PostDelayedTask(new MainThreadPrintTask(), 3000);
    msg_loop.Run();

    thred.Stop();

    return 0;
}