Issue 84 in google-ctemplate: TemplateString has no public accessors for the string contents, so it is impossible to make your own subclass for TemplateDictionaryInterface as there is no way to access the keys

7 views
Skip to first unread message

google-c...@googlecode.com

unread,
Jan 1, 2012, 5:19:51 PM1/1/12
to google-c...@googlegroups.com
Status: New
Owner: ----

New issue 84 by bvgas...@gmail.com: TemplateString has no public accessors
for the string contents, so it is impossible to make your own subclass for
TemplateDictionaryInterface as there is no way to access the keys
http://code.google.com/p/google-ctemplate/issues/detail?id=84

What steps will reproduce the problem?
Try to use a own dictionary (e.g. std::map<std::string, std::string>) as
dictionary, wrapped by extending TemplateDictionaryInterface

What is the expected output? What do you see instead?
I would expect some sort of method to access the key, like 'std::string
ToString() const' or a way to access the raw C data (as I actually need to
bridge it to Lua, which has a C-api).

What version of the product are you using? On what operating system?
1.0 && 1.1

Please provide any additional information below.


google-c...@googlecode.com

unread,
Jan 13, 2012, 1:19:59 PM1/13/12
to google-c...@googlegroups.com
Updates:
Labels: Type-Enhancement Priority-Medium

Comment #1 on issue 84 by csilv...@gmail.com: TemplateString has no public

accessors for the string contents, so it is impossible to make your own
subclass for TemplateDictionaryInterface as there is no way to access the
keys
http://code.google.com/p/google-ctemplate/issues/detail?id=84

} I would expect some sort of method to access the key, like 'std::string

ToString()
} const' or a way to access the raw C data (as I actually need to bridge it
to Lua,
} which has a C-api).

I don't understand what you're asking for here. What exactly are you
trying to do, that you find yourself unable to do?

google-c...@googlecode.com

unread,
Jan 13, 2012, 6:59:07 PM1/13/12
to google-c...@googlegroups.com

Comment #2 on issue 84 by bvgas...@gmail.com: TemplateString has no public
accessors for the string contents, so it is impossible to make your own
subclass for TemplateDictionaryInterface as there is no way to access the
keys
http://code.google.com/p/google-ctemplate/issues/detail?id=84

I want to use my own dictionary implementation (actually bridge it to a Lua
dictionary), so want to define my own `CustomTemplateDictionary' (subclass
of TemplateDictionaryInterface), and implement the GetValue method like

TemplateString GetValue(const TemplateString& variable) const {
return myOwnMap[variable.to_stl_string()];
}

But there is now way to get/fetch/calculate the key-string/key-value from
TemplateString. So implementing your own custom TemplateDictionaryInterface
is impossible (at least how I understand it currently).

google-c...@googlecode.com

unread,
Jan 17, 2012, 2:37:20 PM1/17/12
to google-c...@googlegroups.com

Comment #3 on issue 84 by csilv...@gmail.com: TemplateString has no public
accessors for the string contents, so it is impossible to make your own
subclass for TemplateDictionaryInterface as there is no way to access the
keys
http://code.google.com/p/google-ctemplate/issues/detail?id=84

OK, I understand now -- the issue is with TemplateString.

I purposefully did not make it possible to convert a TemplateString to a
string, because I didn't want people using TemplateString outside the
template library, as a generic string-piece class. So it's designed to
only consume data and not emit it (except to the template library).

The way we do that is through friendship (you can see all the friend
declarations in template_string.h). It would be reasonable to add your own
class in there, but I can see how it would be annoying. Better, I think,
would be to make TemplateDictionaryInterface a friend of TemplateString,
and define two protected methods in TemplateDictionaryInterface, ptr() and
length() (ToString() is probably less efficient than you want to be.)

If you do that, is that enough for you to write the API you need? Feel
free to submit a patch, if you get this working.

google-c...@googlecode.com

unread,
Jan 17, 2012, 2:54:34 PM1/17/12
to google-c...@googlegroups.com

Comment #4 on issue 84 by olafv...@gmail.com: TemplateString has no
public accessors for the string contents, so it is impossible to make your
own subclass for TemplateDictionaryInterface as there is no way to access
the keys
http://code.google.com/p/google-ctemplate/issues/detail?id=84

What about begin() and end() or data() and size() to provide a standard C++
interface?

google-c...@googlecode.com

unread,
Jan 17, 2012, 3:19:46 PM1/17/12
to google-c...@googlegroups.com

Comment #5 on issue 84 by csilv...@gmail.com: TemplateString has no public
accessors for the string contents, so it is impossible to make your own
subclass for TemplateDictionaryInterface as there is no way to access the
keys
http://code.google.com/p/google-ctemplate/issues/detail?id=84

data() and size() sounds fine to me. It doesn't need to be a standard C++
interface, since by design it's not meant to be used outside the template
system, but it doesn't hurt to use the standard names.

Reply all
Reply to author
Forward
0 new messages