Search Results

Search found 40441 results on 1618 pages for 'function templates'.

Page 1/1618 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • PHP: Echo function output in function-line, not line of function call

    - by Brill
    I have a problem with my self-coded template system. The content is inserted by Include(). Now I need to add a meta redirect to one page. I know, meta redirect is not the safest way, but I need it because of it's delay possibility. Now i'm looking for a way to influence the wrapping page (template) by the wrapped page (content). So I thought a function can do this job. <?php function test($testvar){ echo $testvar;} ?> <hr /> <?php test("testtext"); ?> Of course the text echos in the line of the function call, not in the function line. Is there a way to make the function echo in the line of the function itself? In this case above the horizontal rule, not below? Of course every other best pratice for this "template problem" ist welcome! THX

    Read the article

  • Real Excel Templates I

    - by Tim Dexter
    As promised, I'm starting to document the new Excel templates that I teased you all with a few weeks back. Leslie is buried in 11g documentation and will not get to officially documenting the templates for a while. I'll do my best to be professional and not ramble on about this and that, although the weather here has finally turned and its 'scorchio' here in Colorado today. Maybe our stand of Aspen will finally come into leaf ... but I digress. Preamble These templates are not actually that new, I helped in a small way to develop them a few years back with Excel 'meistress' Shirley for a company that was trying to use the Report Manager(RR) Excel FSG outputs under EBS 12. The functionality they needed was just not there in the RR FSG templates, the templates are actually XSL that is created from the the RR Excel template builder and fed to BIP for processing. Think of Excel from our RTF templates and you'll be there ie not really Excel but HTML masquerading as Excel. Although still under controlled release in EBS they have now made their way to the standlone release and are willing to share their Excel goodness. You get everything you have with hte Excel Analyzer Excel templates plus so much more. Therein lies a question, what will happen to the Analyzer templates? My understanding is that both will come together into a single Excel template format some time in the post-11g release world. The new XLSX format for Exce 2007/10 is also in the mix too so watch this space. What more do these templates offer? Well, you can structure data in the Excel output. Similar to RTF templates you can create sheets of data that have master-detail n relationships. Although the analyzer templates can do this, you have to get into macros whereas BIP will do this all for you. You can also use native XSL functions in your data to manipulate it prior to rendering. BP functions are not currently supported. The most impressive, for me at least, is the sheet 'bursting'. You can split your hierarchical data across multiple sheets and dynamically name those sheets. Finally, you of course, still get all the native Excel functionality. Pre-reqs You must be on 10.1.3.4.1 plus the latest rollup patch, 9546699. You can patch upa BIP instance running with OBIEE, no problem You need Excel 2000 or above to build the templates Some patience - there is no Excel template builder for these new templates. So its all going to have to be done by hand. Its not that tough but can get a little 'fiddly'. You can not test the template from Excel , it has to be deployed and then run. Limitations The new templates are definitely superior to the Analyzer templates but there are a few limitations. Re-grouping is not supported. You can only follow a data hierarchy not bend it to your will unless you want to get into macros. No support for BIP functions. The templates support native XSL functions only. No template builder Getting Started The templates make the use of named cells and groups of cells to allow BIP to find the insertion point for data points. It also uses a hidden sheet to store calculation mappings from named cells to XML data elements. To start with, in the great BIP tradition, we need some sample XML data. Becasue I wanted to show the master-detail output we need some hierarchical data. If you have not yet gotten into the data templates, now is a good time, I wrote a post a while back starting from the simple to more complex. They generate ideal data sets for these templates. Im working with the following data set: <EMPLOYEES> <LIST_G_DEPT> <G_DEPT> <DEPARTMENT_ID>10</DEPARTMENT_ID> <DEPARTMENT_NAME>Administration</DEPARTMENT_NAME> <LIST_G_EMP> <G_EMP> <EMPLOYEE_ID>200</EMPLOYEE_ID> <EMP_NAME>Jennifer Whalen</EMP_NAME> <EMAIL>JWHALEN</EMAIL> <PHONE_NUMBER>515.123.4444</PHONE_NUMBER> <HIRE_DATE>1987-09-17T00:00:00.000-06:00</HIRE_DATE> <SALARY>4400</SALARY> </G_EMP> </LIST_G_EMP> <TOTAL_EMPS>1</TOTAL_EMPS> <TOTAL_SALARY>4400</TOTAL_SALARY> <AVG_SALARY>4400</AVG_SALARY> <MAX_SALARY>4400</MAX_SALARY> <MIN_SALARY>4400</MIN_SALARY> </G_DEPT> ... <LIST_G_DEPT> <EMPLOYEES> Simple enough to follow and bread and butter stuff for an RTF template. Building the Template For an Excel template we need to start by thinking about how we want to render the data. Come up with a sample output in Excel. Its all dummy data, nothing marked up yet with one row of data for each level. I have the department name and then a repeating row for the employees. You can apply Excel formatting to the layout. The total is going to be derived from a data element. We'll get to Excel functions later. Marking Up Cells Next we need to start marking up the cells with custom names to map them to data elements. The cell names need to follow a specific format: For data grouping, XDO_GROUP_?group_name? For data elements, XDO_?element_name? Notice the question mark delimter, the group_name and element_name are case sensitive. The next step is to find how to name cells; the easiest method is to highlight the cell and then type in the name. You can also find the Name Manager dialog. I use 2007 and its available on the ribbon under the Formulas section Go thorugh the process of naming all the cells for the element values you have. Using my data set from above.You should end up with something like this in your 'Name Manager' dialog. You can update any mistakes you might have made through this dialog. Creating Groups In the image above you can see there are a couple of named group cells. To create these its a simple case of highlighting the cells that make up the group and then naming them. For the EMP group, highlight the employee row and then type in the name, XDO_GROUP?G_EMP? Notice the 10,000 total is outside of the G_EMP group. Its actually named, XDO_?TOTAL_SALARY?, a query calculated value. For the department group, we need to include the department name cell and the sub EMP grouping and name it, XDO_GROUP?G_DEPT? Notice, the 10,000 total is included in the G_DEPT group. This will ensure it repeats at the department level. Lastly, we do need to include a special sheet in the workbook. We will not have anything meaningful in there for now, but it needs to be present. Create a new sheet and name it XDO_METADATA. The name is important as the BIP rendering engine will looking for it. For our current example we do not need anything other than the required stuff in our XDO_METADATA sheet but, it must be present. Easy enough to hide it. Here's what I have: The only cell that is important is the 'Data Constraints:' cell. The rest is optional. To save curious users getting distracted, hide the metadata sheet. Deploying & Running Templates We should now have a usable Excel template. Loading it into a report is easy enough using the browser UI, just like an RTF template. Set the template type to Excel. You will now be able to run the report and hopefully get something like this. You will not get the red highlighting, thats just some conditional formatting I added to the template using Excel functionality. Your dates are probably going to look raw too. I got around this for now using an Excel function on the cell: =--REPLACE(SUBSTITUTE(E8,"T"," "),LEN(E8)-6,6,"") Google to the rescue on that one. Try some other stuff out. To avoid constantly loading the template through the UI. If you have BIP running locally or you can access the reports repository, once you have loaded the template the first time. Just save the template directly into the report folder. I have put together a sample report using a sample data set, available here. Just drop the xml data file, EmpbyDeptExcelData.xml into 'demo files' folder and you should be good to go. Thats the basics, next we'll start using some XSL functions in the template and move onto the 'bursting' across sheets.

    Read the article

  • jQuery Templates in ASP.NET - Blogs Series

    - by hajan
    In the previous days, I wrote several blog posts related to the great jQuery Templates plugin showing various examples that might help you get started working with the plugin in ASP.NET and VS.NET environment. Here is the list of all five blogs: Introduction to jQuery Templates jQuery Templates - tmpl(), template() and tmplItem() jQuery Templates - {Supported Tags} jQuery Templates with ASP.NET MVC jQuery Templates - XHTML Validation Thank you for reading and wait for my next blogs! All the best, Hajan

    Read the article

  • Using a :default for file names on include templates in SMARTY 3 [closed]

    - by Yohan Leafheart
    Hello everyone, Although I don't think the question was as good as it could be, let me try to explain better here. I have a site using SMARTY 3 as the template system. I have a template structure similar to the below one: /templates/place1/inner_a.tpl /templates/place1/inner_b.tpl /templates/place2/inner_b.tpl /templates/place2/inner_c.tpl /templates/default/inner_a.tpl /templates/default/inner_b.tpl /templates/default/inner_c.tpl These are getting included on the parent template using {include file="{$temp_folder}/{$inner_template}"} So far great. What I wanted to do is having a default for, in the case that the file "{$temp_folder}/{$inner_template}" does not exists, it uses the equivalent file at "default/{$inner_template}". i.e. If I do {include file="place1/inner_c.tpl"}, since that file does not exists it in fact includes "default/inner_c.tpl" Is it possible?

    Read the article

  • MAMP + Python MySQLDB - trouble installing

    - by Frederico
    I'm currently running the latest version of MAMP on my Snow Leopard OSX, and I'm trying to install MySQLDB. Downloaded: MySQL-python-1.2.3c1 I went into the setup_posix.py and adjusted the location of the mysql_config to the one in MAMP: mysql_config.path = "/Applications/MAMP/Library/bin/mysql_config" When trying to build I get the error below. Could anyone give me a hand please: creating build/temp.macosx-10.6-universal-2.6 gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -Dversion_info=(1,2,3,'gamma',1) -D_version_=1.2.3c1 -I/Applications/MAMP/Library/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -fno-omit-frame-pointer -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory _mysql.c:76: error: expected specifier-qualifier-list before ‘MYSQL’ _mysql.c:90: error: expected specifier-qualifier-list before ‘MYSQL_RES’ _mysql.c: In function ‘_mysql_Exception’: _mysql.c:120: warning: implicit declaration of function ‘mysql_errno’ _mysql.c:120: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:123: error: ‘CR_MAX_ERROR’ undeclared (first use in this function) _mysql.c:123: error: (Each undeclared identifier is reported only once _mysql.c:123: error: for each function it appears in.) _mysql.c:131: error: ‘CR_COMMANDS_OUT_OF_SYNC’ undeclared (first use in this function) _mysql.c:132: error: ‘ER_DB_CREATE_EXISTS’ undeclared (first use in this function) _mysql.c:133: error: ‘ER_SYNTAX_ERROR’ undeclared (first use in this function) _mysql.c:134: error: ‘ER_PARSE_ERROR’ undeclared (first use in this function) _mysql.c:135: error: ‘ER_NO_SUCH_TABLE’ undeclared (first use in this function) _mysql.c:136: error: ‘ER_WRONG_DB_NAME’ undeclared (first use in this function) _mysql.c:137: error: ‘ER_WRONG_TABLE_NAME’ undeclared (first use in this function) _mysql.c:138: error: ‘ER_FIELD_SPECIFIED_TWICE’ undeclared (first use in this function) _mysql.c:139: error: ‘ER_INVALID_GROUP_FUNC_USE’ undeclared (first use in this function) _mysql.c:140: error: ‘ER_UNSUPPORTED_EXTENSION’ undeclared (first use in this function) _mysql.c:141: error: ‘ER_TABLE_MUST_HAVE_COLUMNS’ undeclared (first use in this function) _mysql.c:170: error: ‘ER_DUP_ENTRY’ undeclared (first use in this function) _mysql.c:213: warning: implicit declaration of function ‘mysql_error’ _mysql.c:213: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:213: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast _mysql.c: In function ‘_mysql_server_init’: _mysql.c:308: warning: label ‘finish’ defined but not used _mysql.c:234: warning: unused variable ‘item’ _mysql.c:233: warning: unused variable ‘groupc’ _mysql.c:233: warning: unused variable ‘i’ _mysql.c:233: warning: unused variable ‘cmd_argc’ _mysql.c:232: warning: unused variable ‘s’ _mysql.c: In function ‘_mysql_ResultObject_Initialize’: _mysql.c:363: error: ‘MYSQL_RES’ undeclared (first use in this function) _mysql.c:363: error: ‘result’ undeclared (first use in this function) _mysql.c:368: error: ‘MYSQL_FIELD’ undeclared (first use in this function) _mysql.c:368: error: ‘fields’ undeclared (first use in this function) _mysql.c:377: error: ‘_mysql_ResultObject’ has no member named ‘use’ _mysql.c:380: warning: implicit declaration of function ‘mysql_use_result’ _mysql.c:380: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:382: warning: implicit declaration of function ‘mysql_store_result’ _mysql.c:382: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:383: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:386: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:389: warning: implicit declaration of function ‘mysql_num_fields’ _mysql.c:390: error: ‘_mysql_ResultObject’ has no member named ‘nfields’ _mysql.c:391: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:392: warning: implicit declaration of function ‘mysql_fetch_fields’ _mysql.c:438: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ResultObject_traverse’: _mysql.c:450: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:451: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ResultObject_clear’: _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:463: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ConnectionObject_Initialize’: _mysql.c:475: error: ‘MYSQL’ undeclared (first use in this function) _mysql.c:475: error: ‘conn’ undeclared (first use in this function) _mysql.c:500: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:501: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:525: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:547: warning: implicit declaration of function ‘mysql_init’ _mysql.c:547: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:550: warning: implicit declaration of function ‘mysql_options’ _mysql.c:550: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:550: error: ‘MYSQL_OPT_CONNECT_TIMEOUT’ undeclared (first use in this function) _mysql.c:554: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:554: error: ‘MYSQL_OPT_COMPRESS’ undeclared (first use in this function) _mysql.c:555: error: ‘CLIENT_COMPRESS’ undeclared (first use in this function) _mysql.c:558: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:558: error: ‘MYSQL_OPT_NAMED_PIPE’ undeclared (first use in this function) _mysql.c:560: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:560: error: ‘MYSQL_INIT_COMMAND’ undeclared (first use in this function) _mysql.c:562: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:562: error: ‘MYSQL_READ_DEFAULT_FILE’ undeclared (first use in this function) _mysql.c:564: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:564: error: ‘MYSQL_READ_DEFAULT_GROUP’ undeclared (first use in this function) _mysql.c:567: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:567: error: ‘MYSQL_OPT_LOCAL_INFILE’ undeclared (first use in this function) _mysql.c:575: warning: implicit declaration of function ‘mysql_real_connect’ _mysql.c:575: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:590: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c: In function ‘_mysql_ConnectionObject_traverse’: _mysql.c:671: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:672: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ConnectionObject_clear’: _mysql.c:680: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:680: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:680: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:680: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:681: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ConnectionObject_close’: _mysql.c:696: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:698: warning: implicit declaration of function ‘mysql_close’ _mysql.c:698: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:700: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c: In function ‘_mysql_ConnectionObject_affected_rows’: _mysql.c:722: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:723: warning: implicit declaration of function ‘mysql_affected_rows’ _mysql.c:723: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_debug’: _mysql.c:739: warning: implicit declaration of function ‘mysql_debug’ _mysql.c: In function ‘_mysql_ConnectionObject_dump_debug_info’: _mysql.c:757: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:759: warning: implicit declaration of function ‘mysql_dump_debug_info’ _mysql.c:759: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_autocommit’: _mysql.c:783: warning: implicit declaration of function ‘mysql_query’ _mysql.c:783: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_commit’: _mysql.c:806: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_rollback’: _mysql.c:828: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_errno’: _mysql.c:940: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:941: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_error’: _mysql.c:956: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:957: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:957: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast _mysql.c: In function ‘_mysql_escape_string’: _mysql.c:981: warning: implicit declaration of function ‘mysql_escape_string’ _mysql.c: In function ‘_mysql_escape’: _mysql.c:1088: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ResultObject_describe’: _mysql.c:1168: error: ‘MYSQL_FIELD’ undeclared (first use in this function) _mysql.c:1168: error: ‘fields’ undeclared (first use in this function) _mysql.c:1171: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1172: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1173: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1184: warning: implicit declaration of function ‘IS_NOT_NULL’ _mysql.c: In function ‘_mysql_ResultObject_field_flags’: _mysql.c:1204: error: ‘MYSQL_FIELD’ undeclared (first use in this function) _mysql.c:1204: error: ‘fields’ undeclared (first use in this function) _mysql.c:1207: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1208: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1209: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: At top level: _mysql.c:1250: error: expected declaration specifiers or ‘...’ before ‘MYSQL_ROW’ _mysql.c: In function ‘_mysql_row_to_tuple’: _mysql.c:1256: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1258: warning: implicit declaration of function ‘mysql_fetch_lengths’ _mysql.c:1258: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1258: warning: assignment makes pointer from integer without a cast _mysql.c:1261: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:1262: error: ‘row’ undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1275: error: expected declaration specifiers or ‘...’ before ‘MYSQL_ROW’ _mysql.c: In function ‘_mysql_row_to_dict’: _mysql.c:1280: error: ‘MYSQL_FIELD’ undeclared (first use in this function) _mysql.c:1280: error: ‘fields’ undeclared (first use in this function) _mysql.c:1282: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1284: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1284: warning: assignment makes pointer from integer without a cast _mysql.c:1285: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1288: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:1289: error: ‘row’ undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1314: error: expected declaration specifiers or ‘...’ before ‘MYSQL_ROW’ _mysql.c: In function ‘_mysql_row_to_dict_old’: _mysql.c:1319: error: ‘MYSQL_FIELD’ undeclared (first use in this function) _mysql.c:1319: error: ‘fields’ undeclared (first use in this function) _mysql.c:1321: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1323: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1323: warning: assignment makes pointer from integer without a cast _mysql.c:1324: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1327: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:1328: error: ‘row’ undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1350: error: expected declaration specifiers or ‘...’ before ‘MYSQL_ROW’ _mysql.c: In function ‘mysql_fetch_row’: _mysql.c:1361: error: ‘MYSQL_ROW’ undeclared (first use in this function) _mysql.c:1361: error: expected ‘;’ before ‘row’ _mysql.c:1365: error: ‘_mysql_ResultObject’ has no member named ‘use’ _mysql.c:1366: error: ‘row’ undeclared (first use in this function) _mysql.c:1366: warning: implicit declaration of function ‘mysql_fetch_row’ _mysql.c:1366: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1369: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:1372: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:1380: error: too many arguments to function ‘convert_row’ _mysql.c: In function ‘_mysql_ResultObject_fetch_row’: _mysql.c:1404: error: expected declaration specifiers or ‘...’ before ‘MYSQL_ROW’ _mysql.c:1419: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1431: error: ‘_mysql_ResultObject’ has no member named ‘use’ _mysql.c:1445: warning: implicit declaration of function ‘mysql_num_rows’ _mysql.c:1445: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ConnectionObject_character_set_name’: _mysql.c:1512: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c: In function ‘_mysql_get_client_info’: _mysql.c:1603: warning: implicit declaration of function ‘mysql_get_client_info’ _mysql.c:1603: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast _mysql.c: In function ‘_mysql_ConnectionObject_get_host_info’: _mysql.c:1617: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1618: warning: implicit declaration of function ‘mysql_get_host_info’ _mysql.c:1618: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:1618: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast _mysql.c: In function ‘_mysql_ConnectionObject_get_proto_info’: _mysql.c:1632: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1633: warning: implicit declaration of function ‘mysql_get_proto_info’ _mysql.c:1633: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_get_server_info’: _mysql.c:1647: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1648: warning: implicit declaration of function ‘mysql_get_server_info’ _mysql.c:1648: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:1648: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast _mysql.c: In function ‘_mysql_ConnectionObject_info’: _mysql.c:1664: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1665: warning: implicit declaration of function ‘mysql_info’ _mysql.c:1665: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:1665: warning: assignment makes pointer from integer without a cast _mysql.c: In function ‘_mysql_ConnectionObject_insert_id’: _mysql.c:1697: error: ‘my_ulonglong’ undeclared (first use in this function) _mysql.c:1697: error: expected ‘;’ before ‘r’ _mysql.c:1699: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1701: error: ‘r’ undeclared (first use in this function) _mysql.c:1701: warning: implicit declaration of function ‘mysql_insert_id’ _mysql.c:1701: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_kill’: _mysql.c:1718: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1720: warning: implicit declaration of function ‘mysql_kill’ _mysql.c:1720: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_field_count’: _mysql.c:1739: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1741: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ResultObject_num_fields’: _mysql.c:1756: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1757: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ResultObject_num_rows’: _mysql.c:1772: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1773: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ConnectionObject_ping’: _mysql.c:1802: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1803: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:1805: warning: implicit declaration of function ‘mysql_ping’ _mysql.c:1805: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_query’: _mysql.c:1826: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1828: warning: implicit declaration of function ‘mysql_real_query’ _mysql.c:1828: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_select_db’: _mysql.c:1856: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1858: warning: implicit declaration of function ‘mysql_select_db’ _mysql.c:1858: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_shutdown’: _mysql.c:1877: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1879: warning: implicit declaration of function ‘mysql_shutdown’ _mysql.c:1879: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_stat’: _mysql.c:1904: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1906: warning: implicit declaration of function ‘mysql_stat’ _mysql.c:1906: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:1906: warning: assignment makes pointer from integer without a cast _mysql.c: In function ‘_mysql_ConnectionObject_store_result’: _mysql.c:1927: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1928: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:1937: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ConnectionObject_thread_id’: _mysql.c:1966: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1968: warning: implicit declaration of function ‘mysql_thread_id’ _mysql.c:1968: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ConnectionObject_use_result’: _mysql.c:1988: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:1989: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:1998: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ConnectionObject_dealloc’: _mysql.c:2016: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c: In function ‘_mysql_ConnectionObject_repr’: _mysql.c:2028: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:2029: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c: In function ‘_mysql_ResultObject_data_seek’: _mysql.c:2047: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:2048: warning: implicit declaration of function ‘mysql_data_seek’ _mysql.c:2048: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ResultObject_row_seek’: _mysql.c:2061: error: ‘MYSQL_ROW_OFFSET’ undeclared (first use in this function) _mysql.c:2061: error: expected ‘;’ before ‘r’ _mysql.c:2063: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:2064: error: ‘_mysql_ResultObject’ has no member named ‘use’ _mysql.c:2069: error: ‘r’ undeclared (first use in this function) _mysql.c:2069: warning: implicit declaration of function ‘mysql_row_tell’ _mysql.c:2069: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:2070: warning: implicit declaration of function ‘mysql_row_seek’ _mysql.c:2070: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ResultObject_row_tell’: _mysql.c:2082: error: ‘MYSQL_ROW_OFFSET’ undeclared (first use in this function) _mysql.c:2082: error: expected ‘;’ before ‘r’ _mysql.c:2084: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:2085: error: ‘_mysql_ResultObject’ has no member named ‘use’ _mysql.c:2090: error: ‘r’ undeclared (first use in this function) _mysql.c:2090: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:2091: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: In function ‘_mysql_ResultObject_dealloc’: _mysql.c:2099: warning: implicit declaration of function ‘mysql_free_result’ _mysql.c:2099: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c: At top level: _mysql.c:2330: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:2337: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:2344: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:2351: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:2358: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:2421: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:2421: error: initializer element is not constant _mysql.c:2421: error: (near initialization for ‘_mysql_ResultObject_memberlist[0].offset’) _mysql.c: In function ‘_mysql_ConnectionObject_getattr’: _mysql.c:2443: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory _mysql.c:76: error: expected specifier-qualifier-list before ‘MYSQL’ _mysql.c:90: error: expected specifier-qualifier-list before ‘MYSQL_RES’ _mysql.c: In function ‘_mysql_Exception’: _mysql.c:120: warning: implicit declaration of function ‘mysql_errno’ _mysql.c:120: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:123: error: ‘CR_MAX_ERROR’ undeclared (first use in this function) _mysql.c:123: error: (Each undeclared identifier is reported only once _mysql.c:123: error: for each function it appears in.) _mysql.c:131: error: ‘CR_COMMANDS_OUT_OF_SYNC’ undeclared (first use in this function) _mysql.c:132: error: ‘ER_DB_CREATE_EXISTS’ undeclared (first use in this function) _mysql.c:133: error: ‘ER_SYNTAX_ERROR’ undeclared (first use in this function) _mysql.c:134: error: ‘ER_PARSE_ERROR’ undeclared (first use in this function) _mysql.c:135: error: ‘ER_NO_SUCH_TABLE’ undeclared (first use in this function) _mysql.c:136: error: ‘ER_WRONG_DB_NAME’ undeclared (first use in this function) _mysql.c:137: error: ‘ER_WRONG_TABLE_NAME’ undeclared (first use in this function) _mysql.c:138: error: ‘ER_FIELD_SPECIFIED_TWICE’ undeclared (first use in this function) _mysql.c:139: error: ‘ER_INVALID_GROUP_FUNC_USE’ undeclared (first use in this function) _mysql.c:140: error: ‘ER_UNSUPPORTED_EXTENSION’ undeclared (first use in this function) _mysql.c:141: error: ‘ER_TABLE_MUST_HAVE_COLUMNS’ undeclared (first use in this function) _mysql.c:170: error: ‘ER_DUP_ENTRY’ undeclared (first use in this function) _mysql.c:213: warning: implicit declaration of function ‘mysql_error’ _mysql.c:213: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:213: warning: passing argument 1 of ‘PyString_FromString’ makes pointer from integer without a cast _mysql.c: In function ‘_mysql_server_init’: _mysql.c:308: warning: label ‘finish’ defined but not used _mysql.c:234: warning: unused variable ‘item’ _mysql.c:233: warning: unused variable ‘groupc’ _mysql.c:233: warning: unused variable ‘i’ _mysql.c:233: warning: unused variable ‘cmd_argc’ _mysql.c:232: warning: unused variable ‘s’ _mysql.c: In function ‘_mysql_ResultObject_Initialize’: _mysql.c:363: error: ‘MYSQL_RES’ undeclared (first use in this function) _mysql.c:363: error: ‘result’ undeclared (first use in this function) _mysql.c:368: error: ‘MYSQL_FIELD’ undeclared (first use in this function) _mysql.c:368: error: ‘fields’ undeclared (first use in this function) _mysql.c:377: error: ‘_mysql_ResultObject’ has no member named ‘use’ _mysql.c:380: warning: implicit declaration of function ‘mysql_use_result’ _mysql.c:380: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:382: warning: implicit declaration of function ‘mysql_store_result’ _mysql.c:382: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:383: error: ‘_mysql_ResultObject’ has no member named ‘result’ _mysql.c:386: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:389: warning: implicit declaration of function ‘mysql_num_fields’ _mysql.c:390: error: ‘_mysql_ResultObject’ has no member named ‘nfields’ _mysql.c:391: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:392: warning: implicit declaration of function ‘mysql_fetch_fields’ _mysql.c:438: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ResultObject_traverse’: _mysql.c:450: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:451: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ResultObject_clear’: _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:462: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c:463: error: ‘_mysql_ResultObject’ has no member named ‘converter’ _mysql.c: In function ‘_mysql_ConnectionObject_Initialize’: _mysql.c:475: error: ‘MYSQL’ undeclared (first use in this function) _mysql.c:475: error: ‘conn’ undeclared (first use in this function) _mysql.c:500: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:501: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c:525: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:547: warning: implicit declaration of function ‘mysql_init’ _mysql.c:547: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:550: warning: implicit declaration of function ‘mysql_options’ _mysql.c:550: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:550: error: ‘MYSQL_OPT_CONNECT_TIMEOUT’ undeclared (first use in this function) _mysql.c:554: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:554: error: ‘MYSQL_OPT_COMPRESS’ undeclared (first use in this function) _mysql.c:555: error: ‘CLIENT_COMPRESS’ undeclared (first use in this function) _mysql.c:558: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:558: error: ‘MYSQL_OPT_NAMED_PIPE’ undeclared (first use in this function) _mysql.c:560: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:560: error: ‘MYSQL_INIT_COMMAND’ undeclared (first use in this function) _mysql.c:562: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:562: error: ‘MYSQL_READ_DEFAULT_FILE’ undeclared (first use in this function) _mysql.c:564: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:564: error: ‘MYSQL_READ_DEFAULT_GROUP’ undeclared (first use in this function) _mysql.c:567: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:567: error: ‘MYSQL_OPT_LOCAL_INFILE’ undeclared (first use in this function) _mysql.c:575: warning: implicit declaration of function ‘mysql_real_connect’ _mysql.c:575: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’ _mysql.c:590: error: ‘_mysql_ConnectionObject’ has no member named ‘open’ _mysql.c: In function ‘_mysql_ConnectionObject_traverse’: _mysql.c:671: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’ _mysql.c:

    Read the article

  • An Introduction to jQuery Templates

    - by Stephen Walther
    The goal of this blog entry is to provide you with enough information to start working with jQuery Templates. jQuery Templates enable you to display and manipulate data in the browser. For example, you can use jQuery Templates to format and display a set of database records that you have retrieved with an Ajax call. jQuery Templates supports a number of powerful features such as template tags, template composition, and wrapped templates. I’ll concentrate on the features that I think that you will find most useful. In order to focus on the jQuery Templates feature itself, this blog entry is server technology agnostic. All the samples use HTML pages instead of ASP.NET pages. In a future blog entry, I’ll focus on using jQuery Templates with ASP.NET Web Forms and ASP.NET MVC (You can do some pretty powerful things when jQuery Templates are used on the client and ASP.NET is used on the server). Introduction to jQuery Templates The jQuery Templates plugin was developed by the Microsoft ASP.NET team in collaboration with the open-source jQuery team. While working at Microsoft, I wrote the original proposal for jQuery Templates, Dave Reed wrote the original code, and Boris Moore wrote the final code. The jQuery team – especially John Resig – was very involved in each step of the process. Both the jQuery community and ASP.NET communities were very active in providing feedback. jQuery Templates will be included in the jQuery core library (the jQuery.js library) when jQuery 1.5 is released. Until jQuery 1.5 is released, you can download the jQuery Templates plugin from the jQuery Source Code Repository or you can use jQuery Templates directly from the ASP.NET CDN. The documentation for jQuery Templates is already included with the official jQuery documentation at http://api.jQuery.com. The main entry for jQuery templates is located under the topic plugins/templates. A Basic Sample of jQuery Templates Let’s start with a really simple sample of using jQuery Templates. We’ll use the plugin to display a list of books stored in a JavaScript array. Here’s the complete code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>Intro</title> <link href="0_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContent"> <h1>ASP.NET Bookstore</h1> <div id="bookContainer"></div> </div> <script id="bookTemplate" type="text/x-jQuery-tmpl"> <div> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Create an array of books var books = [ { title: "ASP.NET 4 Unleashed", price: 37.79, picture: "AspNet4Unleashed.jpg" }, { title: "ASP.NET MVC Unleashed", price: 44.99, picture: "AspNetMvcUnleashed.jpg" }, { title: "ASP.NET Kick Start", price: 4.00, picture: "AspNetKickStart.jpg" }, { title: "ASP.NET MVC Unleashed iPhone", price: 44.99, picture: "AspNetMvcUnleashedIPhone.jpg" }, ]; // Render the books using the template $("#bookTemplate").tmpl(books).appendTo("#bookContainer"); function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html> When you open this page in a browser, a list of books is displayed: There are several things going on in this page which require explanation. First, notice that the page uses both the jQuery 1.4.4 and jQuery Templates libraries. Both libraries are retrieved from the ASP.NET CDN: <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> You can use the ASP.NET CDN for free (even for production websites). You can learn more about the files included on the ASP.NET CDN by visiting the ASP.NET CDN documentation page. Second, you should notice that the actual template is included in a script tag with a special MIME type: <script id="bookTemplate" type="text/x-jQuery-tmpl"> <div> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> </script> This template is displayed for each of the books rendered by the template. The template displays a book picture, title, and price. Notice that the SCRIPT tag which wraps the template has a MIME type of text/x-jQuery-tmpl. Why is the template wrapped in a SCRIPT tag and why the strange MIME type? When a browser encounters a SCRIPT tag with an unknown MIME type, it ignores the content of the tag. This is the behavior that you want with a template. You don’t want a browser to attempt to parse the contents of a template because this might cause side effects. For example, the template above includes an <img> tag with a src attribute that points at “BookPictures/${picture}”. You don’t want the browser to attempt to load an image at the URL “BookPictures/${picture}”. Instead, you want to prevent the browser from processing the IMG tag until the ${picture} expression is replaced by with the actual name of an image by the jQuery Templates plugin. If you are not worried about browser side-effects then you can wrap a template inside any HTML tag that you please. For example, the following DIV tag would also work with the jQuery Templates plugin: <div id="bookTemplate" style="display:none"> <div> <h2>${title}</h2> price: ${formatPrice(price)} </div> </div> Notice that the DIV tag includes a style=”display:none” attribute to prevent the template from being displayed until the template is parsed by the jQuery Templates plugin. Third, notice that the expression ${…} is used to display the value of a JavaScript expression within a template. For example, the expression ${title} is used to display the value of the book title property. You can use any JavaScript function that you please within the ${…} expression. For example, in the template above, the book price is formatted with the help of the custom JavaScript formatPrice() function which is defined lower in the page. Fourth, and finally, the template is rendered with the help of the tmpl() method. The following statement selects the bookTemplate and renders an array of books using the bookTemplate. The results are appended to a DIV element named bookContainer by using the standard jQuery appendTo() method. $("#bookTemplate").tmpl(books).appendTo("#bookContainer"); Using Template Tags Within a template, you can use any of the following template tags. {{tmpl}} – Used for template composition. See the section below. {{wrap}} – Used for wrapped templates. See the section below. {{each}} – Used to iterate through a collection. {{if}} – Used to conditionally display template content. {{else}} – Used with {{if}} to conditionally display template content. {{html}} – Used to display the value of an HTML expression without encoding the value. Using ${…} or {{= }} performs HTML encoding automatically. {{= }}-- Used in exactly the same way as ${…}. {{! }} – Used for displaying comments. The contents of a {{!...}} tag are ignored. For example, imagine that you want to display a list of blog entries. Each blog entry could, possibly, have an associated list of categories. The following page illustrates how you can use the { if}} and {{each}} template tags to conditionally display categories for each blog entry:   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>each</title> <link href="1_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="blogPostContainer"></div> <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{each categories}} <i>${$value}</i> {{/each}} {{else}} Uncategorized {{/if}} </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> var blogPosts = [ { postTitle: "How to fix a sink plunger in 5 minutes", postEntry: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.", categories: ["HowTo", "Sinks", "Plumbing"] }, { postTitle: "How to remove a broken lightbulb", postEntry: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.", categories: ["HowTo", "Lightbulbs", "Electricity"] }, { postTitle: "New associate website", postEntry: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna." } ]; // Render the blog posts $("#blogPostTemplate").tmpl(blogPosts).appendTo("#blogPostContainer"); </script> </body> </html> When this page is opened in a web browser, the following list of blog posts and categories is displayed: Notice that the first and second blog entries have associated categories but the third blog entry does not. The third blog entry is “Uncategorized”. The template used to render the blog entries and categories looks like this: <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{each categories}} <i>${$value}</i> {{/each}} {{else}} Uncategorized {{/if}} </script> Notice the special expression $value used within the {{each}} template tag. You can use $value to display the value of the current template item. In this case, $value is used to display the value of each category in the collection of categories. Template Composition When building a fancy page, you might want to build a template out of multiple templates. In other words, you might want to take advantage of template composition. For example, imagine that you want to display a list of products. Some of the products are being sold at their normal price and some of the products are on sale. In that case, you might want to use two different templates for displaying a product: a productTemplate and a productOnSaleTemplate. The following page illustrates how you can use the {{tmpl}} tag to build a template from multiple templates:   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Composition</title> <link href="2_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContainer"> <h1>Products</h1> <div id="productListContainer"></div> <!-- Show list of products using composition --> <script id="productListTemplate" type="text/x-jQuery-tmpl"> <div> {{if onSale}} {{tmpl "#productOnSaleTemplate"}} {{else}} {{tmpl "#productTemplate"}} {{/if}} </div> </script> <!-- Show product --> <script id="productTemplate" type="text/x-jQuery-tmpl"> ${name} </script> <!-- Show product on sale --> <script id="productOnSaleTemplate" type="text/x-jQuery-tmpl"> <b>${name}</b> <img src="images/on_sale.png" alt="On Sale" /> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> var products = [ { name: "Laptop", onSale: false }, { name: "Apples", onSale: true }, { name: "Comb", onSale: false } ]; $("#productListTemplate").tmpl(products).appendTo("#productListContainer"); </script> </div> </body> </html>   In the page above, the main template used to display the list of products looks like this: <script id="productListTemplate" type="text/x-jQuery-tmpl"> <div> {{if onSale}} {{tmpl "#productOnSaleTemplate"}} {{else}} {{tmpl "#productTemplate"}} {{/if}} </div> </script>   If a product is on sale then the product is displayed with the productOnSaleTemplate (which includes an on sale image): <script id="productOnSaleTemplate" type="text/x-jQuery-tmpl"> <b>${name}</b> <img src="images/on_sale.png" alt="On Sale" /> </script>   Otherwise, the product is displayed with the normal productTemplate (which does not include the on sale image): <script id="productTemplate" type="text/x-jQuery-tmpl"> ${name} </script>   You can pass a parameter to the {{tmpl}} tag. The parameter becomes the data passed to the template rendered by the {{tmpl}} tag. For example, in the previous section, we used the {{each}} template tag to display a list of categories for each blog entry like this: <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{each categories}} <i>${$value}</i> {{/each}} {{else}} Uncategorized {{/if}} </script>   Another way to create this template is to use template composition like this: <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{tmpl(categories) "#categoryTemplate"}} {{else}} Uncategorized {{/if}} </script> <script id="categoryTemplate" type="text/x-jQuery-tmpl"> <i>${$data}</i> &nbsp; </script>   Using the {{each}} tag or {{tmpl}} tag is largely a matter of personal preference. Wrapped Templates The {{wrap}} template tag enables you to take a chunk of HTML and transform the HTML into another chunk of HTML (think easy XSLT). When you use the {{wrap}} tag, you work with two templates. The first template contains the HTML being transformed and the second template includes the filter expressions for transforming the HTML. For example, you can use the {{wrap}} template tag to transform a chunk of HTML into an interactive tab strip: When you click any of the tabs, you see the corresponding content. This tab strip was created with the following page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Wrapped Templates</title> <style type="text/css"> body { font-family: Arial; background-color:black; } .tabs div { display:inline-block; border-bottom: 1px solid black; padding:4px; background-color:gray; cursor:pointer; } .tabs div.tabState_true { background-color:white; border-bottom:1px solid white; } .tabBody { border-top:1px solid white; padding:10px; background-color:white; min-height:400px; width:400px; } </style> </head> <body> <div id="tabsView"></div> <script id="tabsContent" type="text/x-jquery-tmpl"> {{wrap "#tabsWrap"}} <h3>Tab 1</h3> <div> Content of tab 1. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 2</h3> <div> Content of tab 2. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 3</h3> <div> Content of tab 3. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> {{/wrap}} </script> <script id="tabsWrap" type="text/x-jquery-tmpl"> <div class="tabs"> {{each $item.html("h3", true)}} <div class="tabState_${$index === selectedTabIndex}"> ${$value} </div> {{/each}} </div> <div class="tabBody"> {{html $item.html("div")[selectedTabIndex]}} </div> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Global for tracking selected tab var selectedTabIndex = 0; // Render the tab strip $("#tabsContent").tmpl().appendTo("#tabsView"); // When a tab is clicked, update the tab strip $("#tabsView") .delegate(".tabState_false", "click", function () { var templateItem = $.tmplItem(this); selectedTabIndex = $(this).index(); templateItem.update(); }); </script> </body> </html>   The “source” for the tab strip is contained in the following template: <script id="tabsContent" type="text/x-jquery-tmpl"> {{wrap "#tabsWrap"}} <h3>Tab 1</h3> <div> Content of tab 1. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 2</h3> <div> Content of tab 2. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 3</h3> <div> Content of tab 3. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> {{/wrap}} </script>   The tab strip is created with a list of H3 elements (which represent each tab) and DIV elements (which represent the body of each tab). Notice that the HTML content is wrapped in the {{wrap}} template tag. This template tag points at the following tabsWrap template: <script id="tabsWrap" type="text/x-jquery-tmpl"> <div class="tabs"> {{each $item.html("h3", true)}} <div class="tabState_${$index === selectedTabIndex}"> ${$value} </div> {{/each}} </div> <div class="tabBody"> {{html $item.html("div")[selectedTabIndex]}} </div> </script> The tabs DIV contains all of the tabs. The {{each}} template tag is used to loop through each of the H3 elements from the source template and render a DIV tag that represents a particular tab. The template item html() method is used to filter content from the “source” HTML template. The html() method accepts a jQuery selector for its first parameter. The tabs are retrieved from the source template by using an h3 filter. The second parameter passed to the html() method – the textOnly parameter -- causes the filter to return the inner text of each h3 element. You can learn more about the html() method at the jQuery website (see the section on $item.html()). The tabBody DIV renders the body of the selected tab. Notice that the {{html}} template tag is used to display the tab body so that HTML content in the body won’t be HTML encoded. The html() method is used, once again, to grab all of the DIV elements from the source HTML template. The selectedTabIndex global variable is used to display the contents of the selected tab. Remote Templates A common feature request for jQuery templates is support for remote templates. Developers want to be able to separate templates into different files. Adding support for remote templates requires only a few lines of extra code (Dave Ward has a nice blog entry on this). For example, the following page uses a remote template from a file named BookTemplate.htm: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Remote Templates</title> <link href="0_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContent"> <h1>ASP.NET Bookstore</h1> <div id="bookContainer"></div> </div> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Create an array of books var books = [ { title: "ASP.NET 4 Unleashed", price: 37.79, picture: "AspNet4Unleashed.jpg" }, { title: "ASP.NET MVC Unleashed", price: 44.99, picture: "AspNetMvcUnleashed.jpg" }, { title: "ASP.NET Kick Start", price: 4.00, picture: "AspNetKickStart.jpg" }, { title: "ASP.NET MVC Unleashed iPhone", price: 44.99, picture: "AspNetMvcUnleashedIPhone.jpg" }, ]; // Get the remote template $.get("BookTemplate.htm", null, function (bookTemplate) { // Render the books using the remote template $.tmpl(bookTemplate, books).appendTo("#bookContainer"); }); function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html>   The remote template is retrieved (and rendered) with the following code: // Get the remote template $.get("BookTemplate.htm", null, function (bookTemplate) { // Render the books using the remote template $.tmpl(bookTemplate, books).appendTo("#bookContainer"); });   This code uses the standard jQuery $.get() method to get the BookTemplate.htm file from the server with an Ajax request. After the BookTemplate.htm file is successfully retrieved, the $.tmpl() method is used to render an array of books with the template. Here’s what the BookTemplate.htm file looks like: <div> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> Notice that the template in the BooksTemplate.htm file is not wrapped by a SCRIPT element. There is no need to wrap the template in this case because there is no possibility that the template will get interpreted before you want it to be interpreted. If you plan to use the bookTemplate multiple times – for example, you are paging or sorting the books -- then you should compile the template into a function and cache the compiled template function. For example, the following page can be used to page through a list of 100 products (using iPhone style More paging). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Template Caching</title> <link href="6_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Products</h1> <div id="productContainer"></div> <button id="more">More</button> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Globals var pageIndex = 0; // Create an array of products var products = []; for (var i = 0; i < 100; i++) { products.push({ name: "Product " + (i + 1) }); } // Get the remote template $.get("ProductTemplate.htm", null, function (productTemplate) { // Compile and cache the template $.template("productTemplate", productTemplate); // Render the products renderProducts(0); }); $("#more").click(function () { pageIndex++; renderProducts(); }); function renderProducts() { // Get page of products var pageOfProducts = products.slice(pageIndex * 5, pageIndex * 5 + 5); // Used cached productTemplate to render products $.tmpl("productTemplate", pageOfProducts).appendTo("#productContainer"); } function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html>   The ProductTemplate is retrieved from an external file named ProductTemplate.htm. This template is retrieved only once. Furthermore, it is compiled and cached with the help of the $.template() method: // Get the remote template $.get("ProductTemplate.htm", null, function (productTemplate) { // Compile and cache the template $.template("productTemplate", productTemplate); // Render the products renderProducts(0); });   The $.template() method compiles the HTML representation of the template into a JavaScript function and caches the template function with the name productTemplate. The cached template can be used by calling the $.tmp() method. The productTemplate is used in the renderProducts() method: function renderProducts() { // Get page of products var pageOfProducts = products.slice(pageIndex * 5, pageIndex * 5 + 5); // Used cached productTemplate to render products $.tmpl("productTemplate", pageOfProducts).appendTo("#productContainer"); } In the code above, the first parameter passed to the $.tmpl() method is the name of a cached template. Working with Template Items In this final section, I want to devote some space to discussing Template Items. A new Template Item is created for each rendered instance of a template. For example, if you are displaying a list of 100 products with a template, then 100 Template Items are created. A Template Item has the following properties and methods: data – The data associated with the Template Instance. For example, a product. tmpl – The template associated with the Template Instance. parent – The parent template item if the template is nested. nodes – The HTML content of the template. calls – Used by {{wrap}} template tag. nest – Used by {{tmpl}} template tag. wrap – Used to imperatively enable wrapped templates. html – Used to filter content from a wrapped template. See the above section on wrapped templates. update – Used to re-render a template item. The last method – the update() method -- is especially interesting because it enables you to re-render a template item with new data or even a new template. For example, the following page displays a list of books. When you hover your mouse over any of the books, additional book details are displayed. In the following screenshot, details for ASP.NET Kick Start are displayed. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Template Item</title> <link href="0_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContent"> <h1>ASP.NET Bookstore</h1> <div id="bookContainer"></div> </div> <script id="bookTemplate" type="text/x-jQuery-tmpl"> <div class="bookItem"> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> </script> <script id="bookDetailsTemplate" type="text/x-jQuery-tmpl"> <div class="bookItem"> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} <p> ${description} </p> </div> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Create an array of books var books = [ { title: "ASP.NET 4 Unleashed", price: 37.79, picture: "AspNet4Unleashed.jpg", description: "The most comprehensive book on Microsoft’s new ASP.NET 4.. " }, { title: "ASP.NET MVC Unleashed", price: 44.99, picture: "AspNetMvcUnleashed.jpg", description: "Writing for professional programmers, Walther explains the crucial concepts that make the Model-View-Controller (MVC) development paradigm work…" }, { title: "ASP.NET Kick Start", price: 4.00, picture: "AspNetKickStart.jpg", description: "Visual Studio .NET is the premier development environment for creating .NET applications…." }, { title: "ASP.NET MVC Unleashed iPhone", price: 44.99, picture: "AspNetMvcUnleashedIPhone.jpg", description: "ASP.NET MVC Unleashed for the iPhone…" }, ]; // Render the books using the template $("#bookTemplate").tmpl(books).appendTo("#bookContainer"); // Get compiled details template var bookDetailsTemplate = $("#bookDetailsTemplate").template(); // Add hover handler $(".bookItem").mouseenter(function () { // Get template item associated with DIV var templateItem = $(this).tmplItem(); // Change template to compiled template templateItem.tmpl = bookDetailsTemplate; // Re-render template templateItem.update(); }); function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html>   There are two templates used to display a book: bookTemplate and bookDetailsTemplate. When you hover your mouse over a template item, the standard bookTemplate is swapped out for the bookDetailsTemplate. The bookDetailsTemplate displays a book description. The books are rendered with the bookTemplate with the following line of code: // Render the books using the template $("#bookTemplate").tmpl(books).appendTo("#bookContainer");   The following code is used to swap the bookTemplate and the bookDetailsTemplate to show details for a book: // Get compiled details template var bookDetailsTemplate = $("#bookDetailsTemplate").template(); // Add hover handler $(".bookItem").mouseenter(function () { // Get template item associated with DIV var templateItem = $(this).tmplItem(); // Change template to compiled template templateItem.tmpl = bookDetailsTemplate; // Re-render template templateItem.update(); });   When you hover your mouse over a DIV element rendered by the bookTemplate, the mouseenter handler executes. First, this handler retrieves the Template Item associated with the DIV element by calling the tmplItem() method. The tmplItem() method returns a Template Item. Next, a new template is assigned to the Template Item. Notice that a compiled version of the bookDetailsTemplate is assigned to the Template Item’s tmpl property. The template is compiled earlier in the code by calling the template() method. Finally, the Template Item update() method is called to re-render the Template Item with the bookDetailsTemplate instead of the original bookTemplate. Summary This is a long blog entry and I still have not managed to cover all of the features of jQuery Templates J However, I’ve tried to cover the most important features of jQuery Templates such as template composition, template wrapping, and template items. To learn more about jQuery Templates, I recommend that you look at the documentation for jQuery Templates at the official jQuery website. Another great way to learn more about jQuery Templates is to look at the (unminified) source code.

    Read the article

  • Real Excel Templates 1.5

    - by Tim Dexter
    Not the next installment quite yet, just an update from what I knew yesterday. Right after I posted the Real Excel Templates I. Mike from the PM team got in touch to say he and Shirley had just had a meeting with a customer about the Excel Templates and all the fab features. He included BIPs extended functions, data pre-processing, sub templates and other functionality which was great new news. One caveat, much of the really new stuff, is not quite out in the wild yet. Will let you know as soon as I know more. Shirley and I shared a conversation around being able to re-group data in the templates. It's one of the most powerful features of the RTF template. Providing the ultimate flexibility in layouts. As I wrote yesterday, you need hierarchical data for Excel templates. I stand corrected, 'Of course you can do that in Excel, here's an example' said Shirley 'Very cunning Shirley, very cunning' says I. You can basically use the hidden sheet to re-group the data using native XSL. I'll cover the 'how' later. As you can see Excel templates are the new 'black' with lots of attention and more importantly development cycles to take them forward. Looks like we are going to have a great weekend weather wise here in Colorado. The yard work and pond are beckoning. Maybe the trout will be rising and I can give my rusty fly casting skills a run for their money. I need some stupid fish thou :0) See ya'll next week!

    Read the article

  • how to "think in templates", i.e. how to know that a problem can be solved using templates and how to adapt to it?

    - by sap
    I decided to improve my knowledge of template meta-programming, i know the syntax and rules and been playing with counteless examples from online resources. i understand how powerfull templates can be and how much compile time optimization they can provide but i still cant "think in templates", that is, i cant seem to know by myself if a certain problem could best be solved with templates (instead of something else) and if it can, how to adapt that problem to templates. so what im asking is, is there some kind of online resource or maybe book that teaches how to identify problems that could best be solved with templates and how to adapt that problem. basically i want to learn to "think in templates". already asked on stackoverflow but once again people just redirected me to resources on how to use templates, when im really asking is how to know when to use template meta-programming and how to adapt that problem to templates. thanks in advance.

    Read the article

  • function objects versus function pointers

    - by kumar_m_kiran
    Hi All, I have two questions related to function objects and function pointers, Question : 1 When I read the different uses sort algorithm of STL, I see that the third parameter can be a function objects, below is an example class State { public: //... int population() const; float aveTempF() const; //... }; struct PopLess : public std::binary_function<State,State,bool> { bool operator ()( const State &a, const State &b ) const { return popLess( a, b ); } }; sort( union, union+50, PopLess() ); Question : Now, How does the statement, sort(union, union+50,PopLess()) work? PopLess() must be resolved into something like PopLess tempObject.operator() which would be same as executing the operator () function on a temporary object. I see this as, passing the return value of overloaded operation i.e bool (as in my example) to sort algorithm. So then, How does sort function resolve the third parameter in this case? Question : 2 Question Do we derive any particular advantage of using function objects versus function pointer? If we use below function pointer will it derive any disavantage? inline bool popLess( const State &a, const State &b ) { return a.population() < b.population(); } std::sort( union, union+50, popLess ); // sort by population PS : Both the above references(including example) are from book "C++ Common Knowledge: Essential Intermediate Programming" by "Stephen C. Dewhurst". I was unable to decode the topic content, thus have posted for help. Thanks in advance for your help.

    Read the article

  • Rapidly Deploy Oracle Applications with Oracle VM Templates

    - by monica.kumar
    Oracle today announced Oracle VM Templates for a number of Oracle Applications including Oracle E-Business Suite 12.1 Oracle's JD Edwards Enterprise One 9.0 Oracle's PeopleSoft 9.1 These Oracle VM Templates, based on Oracle Enterprise Linux, provide pre-installed and pre-configured enterprise software images that help eliminate the need to install new software from scratch, offering customers a time-saving approach to deploying a fully configured software stack. Learn more about Oracle VM Templates

    Read the article

  • jQuery Templates - XHTML Validation

    - by hajan
    Many developers have already asked me about this. How to make XHTML valid the web page which uses jQuery Templates. Maybe you have already tried, and I don't know what are your results but here is my opinion regarding this. By default, Visual Studio.NET adds the xhtml1-transitional.dtd schema <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> So, if you try to validate your page which has jQuery Templates against this schema, your page won't be XHTML valid. Why? It's because when creating templates, we use HTML tags inside <script> ... </script> block. Yes, I know that the script block has type="text/html" but it's not supported in this schema, thus it's not valid. Let's try validate the following code Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>     <title>jQuery Templates :: XHTML Validation</title>     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js" type="text/javascript"></script>     <script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js" type="text/javascript"></script>          <script language="javascript" type="text/javascript">         $(function () {             var attendees = [                 { Name: "Hajan", Surname: "Selmani", speaker: true, phones: [070555555, 071888999, 071222333] },                 { Name: "Denis", Surname: "Manski", phones: [070555555, 071222333] }             ];             $("#myTemplate").tmpl(attendees).appendTo("#attendeesList");         });     </script>     <script id="myTemplate" type="text/html">          <li>             ${Name} ${Surname}             {{if speaker}}                 (<font color="red">speaks</font>)             {{else}}                 (attendee)             {{/if}}         </li>     </script>      </head>     <body>     <ol id="attendeesList"></ol> </body> </html> To validate it, go to http://validator.w3.org/#validate_by_input and copy paste the code rendered on client-side browser (it’s almost the same, only the template is rendered inside OL so LI tags are created for each item). Press CHECK and you will get: Result: 1 Errors, 2 warning(s)  The error message says: Validation Output: 1 Error Line 21, Column 13: document type does not allow element "li" here <li> Yes, the <li> HTML element is not allowed inside the <script>, so how to make it valid? FIRST: Using <![CDATA][…]]> The first thing that came in my mind was the CDATA. So, by wrapping any HTML tag which is in script blog, inside <![CDATA[ ........ ]]> it will make our code valid. However, the problem is that the template won't render since the template tags {} cannot get evaluated if they are inside CDATA. Ok, lets try with another approach. SECOND: HTML5 validation Well, if we just remove the strikethrough part bellow of the !DOPCTYPE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> our template is going to be checked as HTML5 and will be valid. Ok, there is another approach I've also tried: THIRD: Separate template to an external file We can separate the template to external file. I didn’t show how to do this previously, so here is the example. 1. Add HTML file with name Template.html in your ASPX website. 2. Place your defined template there without <script> tag Content inside Template.html <li>     ${Name} ${Surname}     {{if speaker}}         (<font color="red">speaks</font>)     {{else}}         (attendee)     {{/if}} </li> 3. Call the HTML file using $.get() jQuery ajax method and render the template with data using $.tmpl() function. $.get("/Templates/Template.html", function (template) {     $.tmpl(template, attendees).appendTo("#attendeesList"); }); So the complete code is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>     <title>jQuery Templates :: XHTML Validation</title>     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js" type="text/javascript"></script>     <script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js" type="text/javascript"></script>          <script language="javascript" type="text/javascript">         $(function () {             var attendees = [                 { Name: "Hajan", Surname: "Selmani", speaker: true, phones: [070555555, 071888999, 071222333] },                 { Name: "Denis", Surname: "Manski", phones: [070555555, 071222333] }             ];             $.get("/Templates/Template.html", function (template) {                 $.tmpl(template, attendees).appendTo("#attendeesList");             });         });     </script>      </head>     <body>     <ol id="attendeesList"></ol> </body> </html> This document was successfully checked as XHTML 1.0 Transitional! Result: Passed If you have any additional methods for XHTML validation, you can share it :). Thanks,Hajan

    Read the article

  • Compiling a program with a legacy version of gcc

    - by wyatt
    This is probably a very difficult problem to troubleshoot with the information I can practically provide, but I'm hoping someone might be able to at least point me in a possible direction. I'm trying to install HTK (http://htk.eng.cam.ac.uk/), which, according to this page needs to be installed using gcc 3.4. Their method of implementing backwards compatibility: #yum install compat-gcc-34-c++ compat-gcc-34 won't work for me as I'm running Ubuntu (On that note, I take it I can't simply install YUM and the subsequent package, since it's an entirely different distro, but if I'm wrong I'd love to hear it). I instead installed two versions of gcc 3.4 - 3.4.0 and 3.4.6 using instructions from this site. I then added the lines suggested by that page to the top of the makefile (on this note, what's the difference between makefile and makefile.in? I tried adding the lines to the top of both files regardless), both for version 3.4.0 and 3.4.6, but both failed. I also tried, on the off-chance, compiling it with my current version (4.4.1), but that also failed. I got the errors: (cd HTKLib && make HTKLib.a) \ || case "" in k) fail=yes;; ) exit 1;; esac; make1: Entering directory /home/charles/bin/htk-3.4/HTKLib' gcc -ansi -D_SVID_SOURCE -DOSS_AUDIO -D'ARCH="i686"' -Wall -Wno-switch -g -O2 -I. -c -o HGraf.o HGraf.c HGraf.c:73:77: error: X11/Xlib.h: No such file or directory HGraf.c:74:23: error: X11/Xutil.h: No such file or directory HGraf.c:75:21: error: X11/Xos.h: No such file or directory HGraf.c:77:27: error: X11/keysymdef.h: No such file or directory HGraf.c:87: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token HGraf.c:88: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rootW’ HGraf.c:91: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘theCmap’ HGraf.c:92: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘theGC’ HGraf.c:93: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gcs’ HGraf.c:95: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token HGraf.c:96: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘report’ HGraf.c:97: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘hints’ HGraf.c:111: error: ‘GXcopy’ undeclared here (not in a function) HGraf.c:111: error: ‘GXor’ undeclared here (not in a function) HGraf.c:111: error: ‘GXxor’ undeclared here (not in a function) HGraf.c:111: error: ‘GXinvert’ undeclared here (not in a function) HGraf.c:151: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token HGraf.c: In function ‘InstallFonts’: HGraf.c:164: error: ‘FontInfo’ undeclared (first use in this function) HGraf.c:164: error: (Each undeclared identifier is reported only once HGraf.c:164: error: for each function it appears in.) HGraf.c:164: warning: implicit declaration of function ‘XLoadQueryFont’ HGraf.c:164: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:167: error: ‘DefaultFont’ undeclared (first use in this function) HGraf.c: At top level: HGraf.c:176: error: expected ‘)’ before ‘*’ token HGraf.c: In function ‘HGetEvent’: HGraf.c:219: error: ‘XEvent’ undeclared (first use in this function) HGraf.c:219: error: expected ‘;’ before ‘xev’ HGraf.c:223: warning: implicit declaration of function ‘XFlush’ HGraf.c:223: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:225: warning: implicit declaration of function ‘XEventsQueued’ HGraf.c:225: error: ‘QueuedAfterFlush’ undeclared (first use in this function) HGraf.c:226: warning: implicit declaration of function ‘XNextEvent’ HGraf.c:226: error: ‘xev’ undeclared (first use in this function) HGraf.c:228: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:230: error: ‘ButtonPress’ undeclared (first use in this function) HGraf.c:235: error: ‘ButtonRelease’ undeclared (first use in this function) HGraf.c:240: error: ‘MotionNotify’ undeclared (first use in this function) HGraf.c:245: error: ‘KeyPress’ undeclared (first use in this function) HGraf.c:249: warning: implicit declaration of function ‘DecodeKeyPress’ HGraf.c:251: error: ‘KeyRelease’ undeclared (first use in this function) HGraf.c:257: error: ‘Expose’ undeclared (first use in this function) HGraf.c: In function ‘HEventsPending’: HGraf.c:281: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:281: error: ‘QueuedAfterFlush’ undeclared (first use in this function) HGraf.c: In function ‘HMousePos’: HGraf.c:288: error: ‘Window’ undeclared (first use in this function) HGraf.c:288: error: expected ‘;’ before ‘root’ HGraf.c:293: warning: implicit declaration of function ‘XQueryPointer’ HGraf.c:293: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:293: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:293: error: ‘root’ undeclared (first use in this function) HGraf.c:293: error: ‘child’ undeclared (first use in this function) HGraf.c: In function ‘InstallColours’: HGraf.c:311: error: ‘XColor’ undeclared (first use in this function) HGraf.c:311: error: expected ‘;’ before ‘greyDef’ HGraf.c:317: warning: implicit declaration of function ‘XParseColor’ HGraf.c:317: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:317: error: ‘theCmap’ undeclared (first use in this function) HGraf.c:317: error: ‘colourDef’ undeclared (first use in this function) HGraf.c:320: warning: implicit declaration of function ‘XAllocColor’ HGraf.c:334: error: ‘whiteDef’ undeclared (first use in this function) HGraf.c:334: warning: implicit declaration of function ‘XQueryColor’ HGraf.c:335: error: ‘blackDef’ undeclared (first use in this function) HGraf.c:341: error: ‘greyDef’ undeclared (first use in this function) HGraf.c: In function ‘HSetColour’: HGraf.c:361: warning: implicit declaration of function ‘XSetForeground’ HGraf.c:361: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:361: error: ‘gcs’ undeclared (first use in this function) HGraf.c: In function ‘HSetGrey’: HGraf.c:370: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:370: error: ‘gcs’ undeclared (first use in this function) HGraf.c: In function ‘HDrawLines’: HGraf.c:388: warning: implicit declaration of function ‘XDrawLines’ HGraf.c:388: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:388: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:388: error: ‘theGC’ undeclared (first use in this function) HGraf.c:388: error: ‘XPoint’ undeclared (first use in this function) HGraf.c:388: error: expected expression before ‘)’ token HGraf.c: In function ‘HDrawRectangle’: HGraf.c:395: warning: implicit declaration of function ‘XDrawRectangle’ HGraf.c:395: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:395: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:395: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HFillRectangle’: HGraf.c:402: warning: implicit declaration of function ‘XFillRectangle’ HGraf.c:402: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:402: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:402: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HDrawLine’: HGraf.c:408: warning: implicit declaration of function ‘XDrawLine’ HGraf.c:408: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:408: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:408: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HFillPolygon’: HGraf.c:414: warning: implicit declaration of function ‘XFillPolygon’ HGraf.c:414: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:414: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:414: error: ‘theGC’ undeclared (first use in this function) HGraf.c:414: error: ‘XPoint’ undeclared (first use in this function) HGraf.c:414: error: expected expression before ‘)’ token HGraf.c: In function ‘HDrawArc’: HGraf.c:427: warning: implicit declaration of function ‘XDrawArc’ HGraf.c:427: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:427: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:427: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HFillArc’: HGraf.c:440: warning: implicit declaration of function ‘XFillArc’ HGraf.c:440: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:440: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:440: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HPrintf’: HGraf.c:451: warning: implicit declaration of function ‘XDrawString’ HGraf.c:451: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:451: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:451: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HCopyArea’: HGraf.c:457: warning: implicit declaration of function ‘XCopyArea’ HGraf.c:457: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:457: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:457: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HPlotVector’: HGraf.c:476: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:476: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:476: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HSetFontSize’: HGraf.c:490: error: ‘CurrentFont’ undeclared (first use in this function) HGraf.c:490: error: ‘DefaultFont’ undeclared (first use in this function) HGraf.c:499: error: ‘FontInfo’ undeclared (first use in this function) HGraf.c:502: warning: implicit declaration of function ‘XSetFont’ HGraf.c:502: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:502: error: ‘gcs’ undeclared (first use in this function) HGraf.c: In function ‘HSetLineWidth’: HGraf.c:511: warning: implicit declaration of function ‘XSetLineAttributes’ HGraf.c:511: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:511: error: ‘gcs’ undeclared (first use in this function) HGraf.c:511: error: ‘LineSolid’ undeclared (first use in this function) HGraf.c:511: error: ‘JoinRound’ undeclared (first use in this function) HGraf.c:511: error: ‘FillSolid’ undeclared (first use in this function) HGraf.c: In function ‘HSetXMode’: HGraf.c:517: error: ‘theGC’ undeclared (first use in this function) HGraf.c:517: error: ‘gcs’ undeclared (first use in this function) HGraf.c: In function ‘CentreX’: HGraf.c:523: warning: implicit declaration of function ‘XTextWidth’ HGraf.c:523: error: ‘CurrentFont’ undeclared (first use in this function) HGraf.c: In function ‘CentreY’: HGraf.c:529: error: ‘CurrentFont’ undeclared (first use in this function) HGraf.c: In function ‘HTextWidth’: HGraf.c:535: error: ‘CurrentFont’ undeclared (first use in this function) HGraf.c: In function ‘HTextHeight’: HGraf.c:541: error: ‘CurrentFont’ undeclared (first use in this function) HGraf.c: In function ‘HDrawImage’: HGraf.c:550: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token HGraf.c:550: error: ‘xi’ undeclared (first use in this function) HGraf.c:557: warning: implicit declaration of function ‘XDestroyImage’ HGraf.c:558: warning: implicit declaration of function ‘XGetImage’ HGraf.c:558: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:558: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:558: error: ‘AllPlanes’ undeclared (first use in this function) HGraf.c:558: error: ‘XYPixmap’ undeclared (first use in this function) HGraf.c:562: warning: implicit declaration of function ‘XPutPixel’ HGraf.c:564: warning: implicit declaration of function ‘XPutImage’ HGraf.c:564: error: ‘theGC’ undeclared (first use in this function) HGraf.c: In function ‘HFlush’: HGraf.c:570: error: ‘theDisp’ undeclared (first use in this function) HGraf.c: In function ‘InitGCs’: HGraf.c:780: error: ‘XGCValues’ undeclared (first use in this function) HGraf.c:780: error: expected ‘;’ before ‘values’ HGraf.c:783: error: ‘GCLineWidth’ undeclared (first use in this function) HGraf.c:783: error: ‘GCFunction’ undeclared (first use in this function) HGraf.c:783: error: ‘GCForeground’ undeclared (first use in this function) HGraf.c:785: error: ‘values’ undeclared (first use in this function) HGraf.c:788: error: ‘gcs’ undeclared (first use in this function) HGraf.c:788: warning: implicit declaration of function ‘XCreateGC’ HGraf.c:788: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:788: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:790: error: ‘GCPlaneMask’ undeclared (first use in this function) HGraf.c: In function ‘InitGlobals’: HGraf.c:800: warning: implicit declaration of function ‘DefaultScreen’ HGraf.c:800: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:801: error: ‘theCmap’ undeclared (first use in this function) HGraf.c:801: warning: implicit declaration of function ‘DefaultColormap’ HGraf.c:802: error: ‘rootW’ undeclared (first use in this function) HGraf.c:802: warning: implicit declaration of function ‘RootWindow’ HGraf.c:803: error: ‘theGC’ undeclared (first use in this function) HGraf.c:803: warning: implicit declaration of function ‘DefaultGC’ HGraf.c:804: error: ‘theVisual’ undeclared (first use in this function) HGraf.c:804: warning: implicit declaration of function ‘DefaultVisual’ HGraf.c:805: warning: implicit declaration of function ‘DisplayCells’ HGraf.c:806: warning: implicit declaration of function ‘DisplayWidth’ HGraf.c:807: warning: implicit declaration of function ‘DisplayHeight’ HGraf.c:808: warning: implicit declaration of function ‘DisplayPlanes’ HGraf.c:809: warning: implicit declaration of function ‘WhitePixel’ HGraf.c:810: warning: implicit declaration of function ‘BlackPixel’ HGraf.c: In function ‘MakeXGraf’: HGraf.c:817: error: ‘Window’ undeclared (first use in this function) HGraf.c:817: error: expected ‘;’ before ‘window’ HGraf.c:818: error: ‘XSetWindowAttributes’ undeclared (first use in this function) HGraf.c:818: error: expected ‘;’ before ‘setwinattr’ HGraf.c:823: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:823: warning: implicit declaration of function ‘XOpenDisplay’ HGraf.c:824: warning: implicit declaration of function ‘XDisplayName’ HGraf.c:828: error: ‘parent’ undeclared (first use in this function) HGraf.c:829: error: ‘window’ undeclared (first use in this function) HGraf.c:829: warning: implicit declaration of function ‘XCreateSimpleWindow’ HGraf.c:831: error: ‘CWBackingStore’ undeclared (first use in this function) HGraf.c:831: error: ‘setwinattr’ undeclared (first use in this function) HGraf.c:831: error: ‘WhenMapped’ undeclared (first use in this function) HGraf.c:832: warning: implicit declaration of function ‘XChangeWindowAttributes’ HGraf.c:834: error: ‘hints’ undeclared (first use in this function) HGraf.c:834: error: ‘PPosition’ undeclared (first use in this function) HGraf.c:834: error: ‘PSize’ undeclared (first use in this function) HGraf.c:834: error: ‘PMaxSize’ undeclared (first use in this function) HGraf.c:834: error: ‘PMinSize’ undeclared (first use in this function) HGraf.c:841: warning: implicit declaration of function ‘XSetStandardProperties’ HGraf.c:841: error: ‘None’ undeclared (first use in this function) HGraf.c:843: warning: implicit declaration of function ‘XSelectInput’ HGraf.c:843: error: ‘ExposureMask’ undeclared (first use in this function) HGraf.c:843: error: ‘KeyPressMask’ undeclared (first use in this function) HGraf.c:843: error: ‘ButtonPressMask’ undeclared (first use in this function) HGraf.c:844: error: ‘ButtonReleaseMask’ undeclared (first use in this function) HGraf.c:844: error: ‘PointerMotionHintMask’ undeclared (first use in this function) HGraf.c:844: error: ‘PointerMotionMask’ undeclared (first use in this function) HGraf.c:845: warning: implicit declaration of function ‘XMapWindow’ HGraf.c:845: error: ‘theWindow’ undeclared (first use in this function) HGraf.c:850: error: ‘report’ undeclared (first use in this function) HGraf.c:851: error: ‘Expose’ undeclared (first use in this function) HGraf.c:852: warning: implicit declaration of function ‘XSendEvent’ HGraf.c:852: error: ‘False’ undeclared (first use in this function) HGraf.c: In function ‘TermHGraf’: HGraf.c:861: error: ‘theDisp’ undeclared (first use in this function) HGraf.c:862: warning: implicit declaration of function ‘XCloseDisplay’ make[1]: *** [HGraf.o] Error 1 make[1]: Leaving directory/home/charles/bin/htk-3.4/HTKLib' make: ** [HTKLib/HTKLib.a] Error 1 Thank you for any help you can provide.

    Read the article

  • When is a SQL function not a function?

    - by Rob Farley
    Should SQL Server even have functions? (Oh yeah – this is a T-SQL Tuesday post, hosted this month by Brad Schulz) Functions serve an important part of programming, in almost any language. A function is a piece of code that is designed to return something, as opposed to a piece of code which isn’t designed to return anything (which is known as a procedure). SQL Server is no different. You can call stored procedures, even from within other stored procedures, and you can call functions and use these in other queries. Stored procedures might query something, and therefore ‘return data’, but a function in SQL is considered to have the type of the thing returned, and can be used accordingly in queries. Consider the internal GETDATE() function. SELECT GETDATE(), SomeDatetimeColumn FROM dbo.SomeTable; There’s no logical difference between the field that is being returned by the function and the field that’s being returned by the table column. Both are the datetime field – if you didn’t have inside knowledge, you wouldn’t necessarily be able to tell which was which. And so as developers, we find ourselves wanting to create functions that return all kinds of things – functions which look up values based on codes, functions which do string manipulation, and so on. But it’s rubbish. Ok, it’s not all rubbish, but it mostly is. And this isn’t even considering the SARGability impact. It’s far more significant than that. (When I say the SARGability aspect, I mean “because you’re unlikely to have an index on the result of some function that’s applied to a column, so try to invert the function and query the column in an unchanged manner”) I’m going to consider the three main types of user-defined functions in SQL Server: Scalar Inline Table-Valued Multi-statement Table-Valued I could also look at user-defined CLR functions, including aggregate functions, but not today. I figure that most people don’t tend to get around to doing CLR functions, and I’m going to focus on the T-SQL-based user-defined functions. Most people split these types of function up into two types. So do I. Except that most people pick them based on ‘scalar or table-valued’. I’d rather go with ‘inline or not’. If it’s not inline, it’s rubbish. It really is. Let’s start by considering the two kinds of table-valued function, and compare them. These functions are going to return the sales for a particular salesperson in a particular year, from the AdventureWorks database. CREATE FUNCTION dbo.FetchSales_inline(@salespersonid int, @orderyear int) RETURNS TABLE AS  RETURN (     SELECT e.LoginID as EmployeeLogin, o.OrderDate, o.SalesOrderID     FROM Sales.SalesOrderHeader AS o     LEFT JOIN HumanResources.Employee AS e     ON e.EmployeeID = o.SalesPersonID     WHERE o.SalesPersonID = @salespersonid     AND o.OrderDate >= DATEADD(year,@orderyear-2000,'20000101')     AND o.OrderDate < DATEADD(year,@orderyear-2000+1,'20000101') ) ; GO CREATE FUNCTION dbo.FetchSales_multi(@salespersonid int, @orderyear int) RETURNS @results TABLE (     EmployeeLogin nvarchar(512),     OrderDate datetime,     SalesOrderID int     ) AS BEGIN     INSERT @results (EmployeeLogin, OrderDate, SalesOrderID)     SELECT e.LoginID, o.OrderDate, o.SalesOrderID     FROM Sales.SalesOrderHeader AS o     LEFT JOIN HumanResources.Employee AS e     ON e.EmployeeID = o.SalesPersonID     WHERE o.SalesPersonID = @salespersonid     AND o.OrderDate >= DATEADD(year,@orderyear-2000,'20000101')     AND o.OrderDate < DATEADD(year,@orderyear-2000+1,'20000101')     ;     RETURN END ; GO You’ll notice that I’m being nice and responsible with the use of the DATEADD function, so that I have SARGability on the OrderDate filter. Regular readers will be hoping I’ll show what’s going on in the execution plans here. Here I’ve run two SELECT * queries with the “Show Actual Execution Plan” option turned on. Notice that the ‘Query cost’ of the multi-statement version is just 2% of the ‘Batch cost’. But also notice there’s trickery going on. And it’s nothing to do with that extra index that I have on the OrderDate column. Trickery. Look at it – clearly, the first plan is showing us what’s going on inside the function, but the second one isn’t. The second one is blindly running the function, and then scanning the results. There’s a Sequence operator which is calling the TVF operator, and then calling a Table Scan to get the results of that function for the SELECT operator. But surely it still has to do all the work that the first one is doing... To see what’s actually going on, let’s look at the Estimated plan. Now, we see the same plans (almost) that we saw in the Actuals, but we have an extra one – the one that was used for the TVF. Here’s where we see the inner workings of it. You’ll probably recognise the right-hand side of the TVF’s plan as looking very similar to the first plan – but it’s now being called by a stack of other operators, including an INSERT statement to be able to populate the table variable that the multi-statement TVF requires. And the cost of the TVF is 57% of the batch! But it gets worse. Let’s consider what happens if we don’t need all the columns. We’ll leave out the EmployeeLogin column. Here, we see that the inline function call has been simplified down. It doesn’t need the Employee table. The join is redundant and has been eliminated from the plan, making it even cheaper. But the multi-statement plan runs the whole thing as before, only removing the extra column when the Table Scan is performed. A multi-statement function is a lot more powerful than an inline one. An inline function can only be the result of a single sub-query. It’s essentially the same as a parameterised view, because views demonstrate this same behaviour of extracting the definition of the view and using it in the outer query. A multi-statement function is clearly more powerful because it can contain far more complex logic. But a multi-statement function isn’t really a function at all. It’s a stored procedure. It’s wrapped up like a function, but behaves like a stored procedure. It would be completely unreasonable to expect that a stored procedure could be simplified down to recognise that not all the columns might be needed, but yet this is part of the pain associated with this procedural function situation. The biggest clue that a multi-statement function is more like a stored procedure than a function is the “BEGIN” and “END” statements that surround the code. If you try to create a multi-statement function without these statements, you’ll get an error – they are very much required. When I used to present on this kind of thing, I even used to call it “The Dangers of BEGIN and END”, and yes, I’ve written about this type of thing before in a similarly-named post over at my old blog. Now how about scalar functions... Suppose we wanted a scalar function to return the count of these. CREATE FUNCTION dbo.FetchSales_scalar(@salespersonid int, @orderyear int) RETURNS int AS BEGIN     RETURN (         SELECT COUNT(*)         FROM Sales.SalesOrderHeader AS o         LEFT JOIN HumanResources.Employee AS e         ON e.EmployeeID = o.SalesPersonID         WHERE o.SalesPersonID = @salespersonid         AND o.OrderDate >= DATEADD(year,@orderyear-2000,'20000101')         AND o.OrderDate < DATEADD(year,@orderyear-2000+1,'20000101')     ); END ; GO Notice the evil words? They’re required. Try to remove them, you just get an error. That’s right – any scalar function is procedural, despite the fact that you wrap up a sub-query inside that RETURN statement. It’s as ugly as anything. Hopefully this will change in future versions. Let’s have a look at how this is reflected in an execution plan. Here’s a query, its Actual plan, and its Estimated plan: SELECT e.LoginID, y.year, dbo.FetchSales_scalar(p.SalesPersonID, y.year) AS NumSales FROM (VALUES (2001),(2002),(2003),(2004)) AS y (year) CROSS JOIN Sales.SalesPerson AS p LEFT JOIN HumanResources.Employee AS e ON e.EmployeeID = p.SalesPersonID; We see here that the cost of the scalar function is about twice that of the outer query. Nicely, the query optimizer has worked out that it doesn’t need the Employee table, but that’s a bit of a red herring here. There’s actually something way more significant going on. If I look at the properties of that UDF operator, it tells me that the Estimated Subtree Cost is 0.337999. If I just run the query SELECT dbo.FetchSales_scalar(281,2003); we see that the UDF cost is still unchanged. You see, this 0.0337999 is the cost of running the scalar function ONCE. But when we ran that query with the CROSS JOIN in it, we returned quite a few rows. 68 in fact. Could’ve been a lot more, if we’d had more salespeople or more years. And so we come to the biggest problem. This procedure (I don’t want to call it a function) is getting called 68 times – each one between twice as expensive as the outer query. And because it’s calling it in a separate context, there is even more overhead that I haven’t considered here. The cheek of it, to say that the Compute Scalar operator here costs 0%! I know a number of IT projects that could’ve used that kind of costing method, but that’s another story that I’m not going to go into here. Let’s look at a better way. Suppose our scalar function had been implemented as an inline one. Then it could have been expanded out like a sub-query. It could’ve run something like this: SELECT e.LoginID, y.year, (SELECT COUNT(*)     FROM Sales.SalesOrderHeader AS o     LEFT JOIN HumanResources.Employee AS e     ON e.EmployeeID = o.SalesPersonID     WHERE o.SalesPersonID = p.SalesPersonID     AND o.OrderDate >= DATEADD(year,y.year-2000,'20000101')     AND o.OrderDate < DATEADD(year,y.year-2000+1,'20000101')     ) AS NumSales FROM (VALUES (2001),(2002),(2003),(2004)) AS y (year) CROSS JOIN Sales.SalesPerson AS p LEFT JOIN HumanResources.Employee AS e ON e.EmployeeID = p.SalesPersonID; Don’t worry too much about the Scan of the SalesOrderHeader underneath a Nested Loop. If you remember from plenty of other posts on the matter, execution plans don’t push the data through. That Scan only runs once. The Index Spool sucks the data out of it and populates a structure that is used to feed the Stream Aggregate. The Index Spool operator gets called 68 times, but the Scan only once (the Number of Executions property demonstrates this). Here, the Query Optimizer has a full picture of what’s being asked, and can make the appropriate decision about how it accesses the data. It can simplify it down properly. To get this kind of behaviour from a function, we need it to be inline. But without inline scalar functions, we need to make our function be table-valued. Luckily, that’s ok. CREATE FUNCTION dbo.FetchSales_inline2(@salespersonid int, @orderyear int) RETURNS table AS RETURN (SELECT COUNT(*) as NumSales     FROM Sales.SalesOrderHeader AS o     LEFT JOIN HumanResources.Employee AS e     ON e.EmployeeID = o.SalesPersonID     WHERE o.SalesPersonID = @salespersonid     AND o.OrderDate >= DATEADD(year,@orderyear-2000,'20000101')     AND o.OrderDate < DATEADD(year,@orderyear-2000+1,'20000101') ); GO But we can’t use this as a scalar. Instead, we need to use it with the APPLY operator. SELECT e.LoginID, y.year, n.NumSales FROM (VALUES (2001),(2002),(2003),(2004)) AS y (year) CROSS JOIN Sales.SalesPerson AS p LEFT JOIN HumanResources.Employee AS e ON e.EmployeeID = p.SalesPersonID OUTER APPLY dbo.FetchSales_inline2(p.SalesPersonID, y.year) AS n; And now, we get the plan that we want for this query. All we’ve done is tell the function that it’s returning a table instead of a single value, and removed the BEGIN and END statements. We’ve had to name the column being returned, but what we’ve gained is an actual inline simplifiable function. And if we wanted it to return multiple columns, it could do that too. I really consider this function to be superior to the scalar function in every way. It does need to be handled differently in the outer query, but in many ways it’s a more elegant method there too. The function calls can be put amongst the FROM clause, where they can then be used in the WHERE or GROUP BY clauses without fear of calling the function multiple times (another horrible side effect of functions). So please. If you see BEGIN and END in a function, remember it’s not really a function, it’s a procedure. And then fix it. @rob_farley

    Read the article

  • jQuery templates - Load another template within a template (composite)

    - by Saxman
    I'm following this post by Dave Ward (http://encosia.com/2010/12/02/jquery-templates-composite-rendering-and-remote-loading/) to load a composite templates for a Blog, where I have a total of 3 small templates (all in one file) for a blog post. In the template file, I have these 3 templates: blogTemplate, where I render the "postTemplate" Inside the "postTemplate", I would like to render another template that displays comments, I called this "commentsTemplate" the "commentsTemplate" Here's the structure of my json data: blog Title Content PostedDate Comments (a collection of comments) CommentContents CommentedBy CommentedDate For now, I was able to render the Post content using the code below: Javascript $(document).ready(function () { $.get('/GetPost', function (data) { $.get('/Content/Templates/_postWithComments.tmpl.htm', function (templates) { $('body').append(templates); $('#blogTemplate').tmpl(data).appendTo('#blogPost'); }); }); }); Templates <!--Blog Container Templates--> <script id="blogTemplate" type="x-jquery-tmpl"> <div class="latestPost"> {{tmpl() '#postTemplate'}} </div> </script> <!--Post Item Container--> <script id="postTemplate" type="x-jquery-tmpl"> <h2> ${Title}</h2> <div class="entryHead"> Posted in <a class="category" rel="#">Design</a> on ${PostedDateString} <a class="comments" rel="#">${NumberOfComments} Comments</a></div> ${Content} <div class="tags"> {{if Tags.length}} <strong>Tags:</strong> {{each(i, tag) Tags}} <a class="tag" href="/blog/tags/{{= tag.Name}}"> {{= tag.Name}}</a> {{/each}} <a class="share" rel="#"><strong>TELL A FRIEND</strong></a> <a class="share twitter" rel="#">Twitter</a> <a class="share facebook" rel="#">Facebook</a> {{/if}} </div> <!-- close .tags --> <!-- end Entry 01 --> {{if Comments.length}} {{each(i, comment) Comments}} {{tmpl() '#commentTemplate'}} {{/each}} {{/if}} <div class="lineHor"> </div> </script> <!--Comment Items Container--> <script id="commentTemplate" type="x-jquery-tmpl"> <h4> Comments</h4> &nbsp; <!-- COMMENT --> <div id="authorComment1"> <div id="gravatar1" class="grid_2"> <!--<img src="images/gravatar.png" alt="" />--> </div> <!-- close #gravatar --> <div id="commentText1"> <span class="replyHead">by<a class="author" rel="#">${= comment.CommentedBy}</a>on today</span> <p> {{= comment.CommentContents}}</p> </div> <!-- close #commentText --> <div id="quote1"> <a class="quote" rel="#"><strong>Quote this Comment</strong></a> </div> <!-- close #quote --> </div> <!-- close #authorComment --> <!-- END COMMENT --> </script> Where I'm having problem is at the {{each(i, comment) Comments}} {{tmpl() '#commentTemplate'}} {{/each}} Update - Example Json data when GetPost method is called { Id: 1, Title: "Test Blog", Content: "This is a test post asdf asdf asdf asdf asdf", PostedDateString: "2010-12-20", - Comments: [ - { Id: 1, PostId: 1, CommentContents: "Test comments # 1, asdf asdf asdf", PostedBy: "User 1", CommentedDate: "2010-12-20" }, - { Id: 2, PostId: 1, CommentContents: "Test comments # 2, ghjk gjjk gjkk", PostedBy: "User 2", CommentedDate: "2010-12-21" } ] } I've tried passing in {{tmpl(comment) ..., {{tmpl(Comments) ..., or leave {{tmpl() ... but none seems to work. I don't know how to iterate over the Comments collection and pass that object into the commentsTemplate. Any suggestions? Thank you very much.

    Read the article

  • How to convert a lambda to an std::function using templates

    - by retep998
    Basically, what I want to be able to do is take a lambda with any number of any type of parameters and convert it to an std::function. I've tried the following and neither method works. std::function([](){});//Complains that std::function is missing template parameters template <typename T> void foo(function<T> f){} foo([](){});//Complains that it cannot find a matching candidate The following code does work however, but it is not what I want because it requires explicitly stating the template parameters which does not work for generic code. std::function<void()>([](){}); I've been mucking around with functions and templates all evening and I just can't figure this out, so any help would be much appreciated. As mentioned in a comment, the reason I'm trying to do this is because I'm trying to implement currying in C++ using variadic templates. Unfortunately, this fails horribly when using lambdas. For example, I can pass a standard function using a function pointer. template <typename R, typename...A> void foo(R (*f)(A...)) {} void bar() {} int main() { foo(bar); } However, I can't figure out how to pass a lambda to such a variadic function. Why I'm interested in converting a generic lambda into an std::function is because I can do the following, but it ends up requiring that I explicitly state the template parameters to std::function which is what I am trying to avoid. template <typename R, typename...A> void foo(std::function<R(A...)>) {} int main() { foo(std::function<void()>([](){})); }

    Read the article

  • MYSQL stored function - create function (function definition) problem using FORMAT

    - by Jason Fonseca
    Hi all, I keep receiving an error with the following code. I am trying to make a function that will format a field (content=0.0032) into a varchar/percent (content=0.32%). At the moment i'm just trying to get format to work, and it throws up an error "Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'len);" The function definition for "Format" is "Format(X,d)" where x is the number and d is the number of decimal places to round too. It then should output a string ###,###,###.## etc. My code is as follows: DROP FUNCTION IF EXISTS percent; DELIMITER $$ CREATE /*[DEFINER = { user | CURRENT_USER }]*/ FUNCTION `auau7859_aba`.`percent`(num DOUBLE, len INT) RETURNS VARCHAR(10) DETERMINISTIC BEGIN RETURN FORMAT(num,len); END$$ DELIMITER ; Save me...Luke

    Read the article

  • Can overloading is possible with two version of function, constant member function and function with

    - by GG
    Hello, I just came across various overloading methods like type of parameter passed, varying number of parameters, return type etc. I just want to know that can I overload a function with following two version //function which can modify member String& MyClass::doSomething(); //constant member function String& MyClass::doSomething() const; Please let me know the reason behind it. Thanks, GG

    Read the article

  • Django-like templates system for Java?

    - by Savash
    I'm looking for the templates engine for Java with syntax like in Django templates or Twig (PHP). Is it exists? Update: The target is to have same templates files for different languages. File index.tpl {{head}} {{ var|escape }} {{body}} can be rendered from python (Django) code as well as from PHP, using Twig. I'm looking for Java solution. Thanks.

    Read the article

  • jQuery Templates - {Supported Tags}

    - by hajan
    I have started with Introduction to jQuery Templates, then jQuery Templates - tmpl(), template() and tmplItem() functions. In this blog we will see what supported tags are available in the jQuery Templates plugin.Template tags can be used inside template together in combination with HTML tags and plain text, which helps to iterate over JSON data. Up to now, there are several supported tags in jQuery Templates plugin: ${expr} or {{= expr}} {{each itemArray}} … {{/each}} {{if condition}} … {{else}} … {{/if}} {{html …}} {{tmpl …}} {{wrap …}} … {{/wrap}}   - ${expr} or {{= expr}} Is used for insertion of data values in the rendered template. It can evaluate fields, functions or expression. Example: <script id="attendeesTemplate" type="text/html">     <li> ${Name} {{= Surname}} </li>         </script> Either ${Name} or {{= Surname}} (with blank space between =<blankspace>Field) will work.   - {{each itemArray}} … {{/each}} each is everywhere the same "(for)each", used to loop over array or collection Example: <script id="attendeesTemplate" type="text/html">     <li>         ${Name} ${Surname}         {{if speaker}}             (<font color="red">speaks</font>)         {{else}}             (attendee)         {{/if}}                 {{each phones}}                             <br />             ${$index}: <em>${$value}</em>         {{/each}}             </li> </script> So, you see we can use ${$index} and ${$value} to get the current index and value while iterating over the item collection. Alternatively, you can add index,value on the following way: {{each(i,v) phones}}     <br />     ${i}: <em>${v}</em> {{/each}} Result would be: Here is complete working example that you can run and see the result: <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">     <title>Nesting and Looping Example :: jQuery Templates</title>     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js" type="text/javascript"></script>     <script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js" type="text/javascript"></script>     <script language="javascript" type="text/javascript">         $(function () {             var attendees = [                 { Name: "Hajan", Surname: "Selmani", speaker: true, phones:[070555555, 071888999, 071222333] },                 { Name: "Someone", Surname: "Surname", phones: [070555555, 071222333] },                 { Name: "Third", Surname: "Thirdsurname", phones: [070555555, 071888999, 071222333] },             ];             $("#attendeesTemplate").tmpl(attendees).appendTo("#attendeesList");         });     </script>     <script id="attendeesTemplate" type="text/html">         <li>             ${Name} ${Surname}             {{if speaker}}                 (<font color="red">speaks</font>)             {{else}}                 (attendee)             {{/if}}                     {{each(i,v) phones}}                 <br />                 ${i}: <em>${v}</em>             {{/each}}                 </li>     </script> </head> <body>     <ol id="attendeesList"></ol>     </body> </html>   - {{if condition}} … {{else}} … {{/if}} Standard if/else statement. Of course, you can use it without the {{else}} if you have such condition to check, however closing the {{/if}} tag is required. Example: {{if speaker}}     (<font color="red">speaks</font>) {{else}}     (attendee) {{/if}} You have this same code block in the above complete example showing the 'each' cycle ;).   - {{html …}} Is used for insertion of HTML markup strings in the rendered template. Evaluates the specified field on the current data item, or the specified JavaScript function or expression. Example: - without {{html …}} <script language="javascript" type="text/javascript">   $(function () {   var attendees = [             { Name: "Hajan", Surname: "Selmani", Info: "He <font color='red'>is the speaker of today's</font> session", speaker: true },         ];   $("#myTemplate").tmpl(attendees).appendTo("#speakers"); }); </script> <script id="myTemplate" type="text/html">     ${Name} ${Surname} <br />     ${Info} </script> Result: - with {{html …}} <script language="javascript" type="text/javascript">   $(function () {   var attendees = [             { Name: "Hajan", Surname: "Selmani", Info: "He <font color='red'>is the speaker of today's</font> session", speaker: true },         ];   $("#myTemplate").tmpl(attendees).appendTo("#speakers"); }); </script> <script id="myTemplate" type="text/html">     ${Name} ${Surname} <br />     {{html Info}} </script> Result:   - {{wrap …}} It’s used for composition and incorporation of wrapped HTML. It’s similar to {{tmpl}} Example: <script id="myTmpl" type="text/html">     <div id="personInfo">     <br />     ${Name} ${Surname}     {{wrap "#myWrapper"}}         <h2>${Info}</h2>         <div>             {{if speaker}}                 (speaker)             {{else}}                 (attendee)             {{/if}}         </div>     {{/wrap}}     </div> </script> <script id="myWrapper" type="text/html">     <table><tbody>         <tr>             {{each $item.html("div")}}                 <td>                     {{html $value}}                 </td>             {{/each}}         </tr>     </tbody></table> </script> All the HTMl content inside the {{wrap}} … {{/wrap}} is available to the $item.html(filter, textOnly) method. In our example, we have defined some standard template and created wrapper which calls the other template with id myWrapper. Then using $item.html(“div”) we find the div tag and render the html value (together with the div tag) inside the <td> … </td>. So, here inside td the <div> <speaker or attendee depending of the condition> </div>  will be rendered. The HTML output from this is:   - {{tmpl …}} Used for composition as template items Example: <script id="myTemplate" type="text/html">     <div id="bookItem">         <div id="bookCover">             {{tmpl "#bookCoverTemplate"}}         </div>         <div id="bookDetails">             <div id="book">                             ${title} - ${author}             </div>             <div id="price">$${price}</div>             <div id="Details">${pages} pgs. - ${year} year</div>         </div>     </div> </script> <script id="bookCoverTemplate" type="text/html">     <img src="${image}" alt="${title} Image" /> </script> In this example, using {{tmpl “#bookCoverTemplate”}} I’m calling another template inside the first template. In the other template I’ve created template for a book cover. The rendered HTML of this is: and   So we have seen example for each of the tags that are right now available in the jQuery Templates (beta) plugin which is created by Microsoft as a contribution to the open source jQuery Project. I hope this was useful blog post for you. Regards, HajanNEXT - jQuery Templates with ASP.NET MVC

    Read the article

  • C++, function pointer to the template function pointer

    - by Ian
    I am having a pointer to the common static method class MyClass { private: static double ( *pfunction ) ( const Object *, const Object *); ... }; pointing to the static method class SomeClass { public: static double getA ( const Object *o1, const Object *o2); ... }; Initialization: double ( *MyClass::pfunction ) ( const Object *o1, const Object *o2 ) = &SomeClass::getA; I would like to convert this pointer to the static template function pointer: template <class T> static T ( *pfunction ) ( const Object <T> *, const Object <T> *); //Compile error where: class SomeClass { public: template <class T> static double getA ( const Object <T> *o1, const Object <T> *o2); ... }; But there is some error... Thanks for your help...

    Read the article

  • C++ Pointer member function with templates assignment with a member function of another class

    - by Agusti
    Hi, I have this class: class IShaderParam{ public: std::string name_value; }; template<class TParam> class TShaderParam:public IShaderParam{ public: void (TShaderParam::*send_to_shader)( const TParam&,const std::string&); TShaderParam():send_to_shader(NULL){} TParam value; void up_to_shader(); }; typedef TShaderParam<float> FloatShaderParam; typedef TShaderParam<D3DXVECTOR3> Vec3ShaderParam; In another class, I have a vector of IShaderParams* and functions that i want to send to "send_to_shader". I'm trying assign the reference of these functions like this: Vec3ShaderParam *_param = new Vec3ShaderParam; _param-send_to_shader = &TShader::setVector3; This is the function: void TShader::setVector3(const D3DXVECTOR3 &vec, const std::string &name){ //... } And this is the class with IshaderParams*: class TShader{ std::vector params; public: Shader effect; std::string technique_name; TShader(std::string& afilename):effect(NULL){}; ~TShader(); void setVector3(const D3DXVECTOR3 &vec, const std::string &name); When I compile the project with Visual Studio C++ Express 2008 I recieve this error: Error 2 error C2440: '=' :can't make the conversion 'void (__thiscall TShader::* )(const D3DXVECTOR3 &,const std::string &)' a 'void (__thiscall TShaderParam::* )(const TParam &,const std::string &)' c:\users\isagoras\documents\mcv\afoc\shader.cpp 127 Can I do the assignment? No? I don't know how :-S Yes, I know that I can achieve the same objective with other techniques, but I want to know how can I do this..

    Read the article

  • jQuery Templates with ASP.NET MVC

    - by hajan
    In my three previous blogs, I’ve shown how to use Templates in your ASPX website. Introduction to jQuery TemplatesjQuery Templates - tmpl(), template() and tmplItem()jQuery Templates - {Supported Tags}Now, I will show one real-world example which you may use it in your daily work of developing applications with ASP.NET MVC and jQuery. In the following example I will use Pubs database so that I will retrieve values from the authors table. To access the data, I’m using Entity Framework. Let’s pass throughout each step of the scenario: 1. Create new ASP.NET MVC Web application 2. Add new View inside Home folder but do not select a master page, and add Controller for your View 3. BODY code in the HTML <body>     <div>         <h1>Pubs Authors</h1>         <div id="authorsList"></div>     </div> </body> As you can see  in the body we have only one H1 tag and a div with id authorsList where we will append the data from database.   4. Now, I’ve created Pubs model which is connected to the Pub database and I’ve selected only the authors table in my EDMX model. You can use your own database. 5. Next, lets create one method of JsonResult type which will get the data from database and serialize it into JSON string. public JsonResult GetAuthors() {     pubsEntities pubs = new pubsEntities();     var authors = pubs.authors.ToList();     return Json(authors, JsonRequestBehavior.AllowGet); } So, I’m creating object instance of pubsEntities and get all authors in authors list. Then returning the authors list by serializing it to JSON using Json method. The JsonRequestBehaviour.AllowGet parameter is used to make the GET requests from the client become allowed. By default in ASP.NET MVC 2 the GET is not allowed because of security issue with JSON hijacking.   6. Next, lets create jQuery AJAX function which will call the GetAuthors method. We will use $.getJSON jQuery method. <script language="javascript" type="text/javascript">     $(function () {         $.getJSON("GetAuthors", "", function (data) {             $("#authorsTemplate").tmpl(data).appendTo("#authorsList");         });     }); </script>   Once the web page is downloaded, the method will be called. The first parameter of $.getJSON() is url string in our case the method name. The second parameter (which in the example is empty string) is the key value pairs that will be send to the server, and the third function is the callback function or the result which is going to be returned from the server. Inside the callback function we have code that renders data with template which has id #authorsTemplate and appends it to element which has #authorsList ID.   7. The jQuery Template <script id="authorsTemplate" type="text/html">     <div id="author">         ${au_lname} ${au_fname}         <div id="address">${address}, ${city}</div>         <div id="contractType">                     {{if contract}}             <font color="green">Has contract with the publishing house</font>         {{else}}             <font color="red">Without contract</font>         {{/if}}         <br />         <em> ${printMessage(state)} </em>         <br />                     </div>     </div> </script> As you can see, I have tags containing fields (au_lname, au_fname… etc.) that corresponds to the table in the EDMX model which is the same as in the database. One more thing to note here is that I have printMessage(state) function which is called inside ${ expression/function/field } tag. The printMessage function <script language="javascript" type="text/javascript">     function printMessage(s) {         if (s=="CA") return "The author is from California";         else return "The author is not from California";     } </script> So, if state is “CA” print “The author is from California” else “The author is not from California”   HERE IS THE COMPLETE ASPX CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Database Example :: jQuery Templates</title>     <style type="text/css">         body           {             font-family:Verdana,Arial,Courier New, Sans-Serif;             color:Black;             padding:2px, 2px, 2px, 2px;             background-color:#FF9640;         }         #author         {             display:block;             float:left;             text-decoration:none;             border:1px solid black;             background-color:White;             padding:20px 20px 20px 20px;             margin-top:2px;             margin-right:2px;             font-family:Verdana;             font-size:12px;             width:200px;             height:70px;}         #address           {             font-style:italic;             color:Blue;             font-size:12px;             font-family:Verdana;         }         .author_hover {background-color:Yellow;}     </style>     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js" type="text/javascript"></script>     <script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js" type="text/javascript"></script>     <script language="javascript" type="text/javascript">         function printMessage(s) {             if (s=="CA") return "The author is from California";             else return "The author is not from California";         }     </script>     <script id="authorsTemplate" type="text/html">         <div id="author">             ${au_lname} ${au_fname}             <div id="address">${address}, ${city}</div>             <div id="contractType">                         {{if contract}}                 <font color="green">Has contract with the publishing house</font>             {{else}}                 <font color="red">Without contract</font>             {{/if}}             <br />             <em> ${printMessage(state)} </em>             <br />                         </div>         </div>     </script>     <script language="javascript" type="text/javascript">         $(function () {             $.getJSON("GetAuthors", "", function (data) {                 $("#authorsTemplate").tmpl(data).appendTo("#authorsList");             });         });     </script> </head>     <body>     <div id="title">Pubs Authors</div>     <div id="authorsList"></div> </body> </html> So, in the complete example you also have the CSS style I’m using to stylize the output of my page. Here is print screen of the end result displayed on the web page: You can download the complete source code including examples shown in my previous blog posts about jQuery templates and PPT presentation from my last session I had in the local .NET UG meeting in the following DOWNLOAD LINK. Do let me know your feedback. Regards, Hajan

    Read the article

  • Find odd and even rows using $.inArray() function when using jQuery Templates

    - by hajan
    In the past period I made series of blogs on ‘jQuery Templates in ASP.NET’ topic. In one of these blogs dealing with jQuery Templates supported tags, I’ve got a question how to create alternating row background. When rendering the template, there is no direct access to the item index. One way is if there is an incremental index in the JSON string, we can use it to solve this. If there is not, then one of the ways to do this is by using the jQuery’s $.inArray() function. - $.inArray(value, array) – similar to JavaScript indexOf() Here is an complete example how to use this in context of jQuery Templates: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <style type="text/css">         #myList { cursor:pointer; }                  .speakerOdd { background-color:Gray; color:White;}         .speaker { background-color:#443344; color:White;}                  .speaker:hover { background-color:White; color:Black;}         .speakerOdd:hover { background-color:White; color:Black;}     </style>     <title>jQuery ASP.NET</title>     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js" type="text/javascript"></script>     <script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js" type="text/javascript"></script>     <script language="javascript" type="text/javascript">         var speakers = [             { Name: "Hajan1" },             { Name: "Hajan2" },             { Name: "Hajan3" },             { Name: "Hajan4" },             { Name: "Hajan5" }         ];         $(function () {             $("#myTemplate").tmpl(speakers).appendTo("#myList");         });         function oddOrEven() {             return ($.inArray(this.data, speakers) % 2) ? "speaker" : "speakerOdd";         }     </script>     <script id="myTemplate" type="text/x-jquery-tmpl">         <tr class="${oddOrEven()}">             <td> ${Name}</td>         </tr>     </script> </head> <body>     <table id="myList"></table> </body> </html> So, I have defined stylesheet classes speakerOdd and speaker as well as corresponding :hover styles. Then, you have speakers JSON string containing five items. And what is most important in our case is the oddOrEven function where $.inArray(value, data) is implemented. function oddOrEven() {     return ($.inArray(this.data, speakers) % 2) ? "speaker" : "speakerOdd"; } Remark: The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, $.inArray() returns 0. From http://api.jquery.com/jQuery.inArray/ So, now we can call oddOrEven function from inside our jQuery Template in the following way: <script id="myTemplate" type="text/x-jquery-tmpl">     <tr class="${oddOrEven()}">         <td> ${Name}</td>     </tr> </script> And the result is I hope you like it. Regards, Hajan

    Read the article

  • How do you handle increasingly long compile times when working with templates?

    - by Ghita
    I use Visual Studio 2012 and he have cases where we added templates parameters to a class "just" in order to introduce a "seam point" so that in unit-test we can replace those parts with mock objects. How do you usually introduce seam points in C++: using interfaces and/or mixing based on some criteria with implicit interfaces by using templates parameters also ? One reason to ask this is also because when compiling sometimes a single C++ file (that includes templates files, that could also include other templates) results in an object file being generated that takes in the order of around 5-10 seconds on a developer machine. VS compiler is also not particularly fast on compiling templates as far as I understand, and because of the templates inclusion model (you practically include the definition of the template in every file that uses it indirectly and possibly re-instantiate that template every time you modify something that has nothing to do with that template) you could have problems with compile times (when doing incremental compiling). What are your ways of handling incremental(and not only) compile time when working with templates (besides a better/faster compiler :-)).

    Read the article

  • eventmachine on debian fails install via rubygems

    - by Max
    this has been killing me for the last 5 hours. I don't seem to be able to get eventmachine running on my debian box. here this output: $ gem install thin Building native extensions. This could take a while... ERROR: Error installing thin: ERROR: Failed to build gem native extension. /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb checking for rb_trap_immediate in ruby.h,rubysig.h... no checking for rb_thread_blocking_region()... yes checking for inotify_init() in sys/inotify.h... yes checking for writev() in sys/uio.h... yes checking for rb_wait_for_single_fd()... yes checking for rb_enable_interrupt()... yes checking for rb_time_new()... yes checking for sys/event.h... no checking for epoll_create() in sys/epoll.h... yes creating Makefile make compiling kb.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from kb.cpp:20: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from kb.cpp:20: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from kb.cpp:20: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from kb.cpp:20: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type compiling rubymain.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from rubymain.cpp:20: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from rubymain.cpp:20: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from rubymain.cpp:20: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from rubymain.cpp:20: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type compiling ssl.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from ssl.cpp:23: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from ssl.cpp:23: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from ssl.cpp:23: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from ssl.cpp:23: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type compiling cmain.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from cmain.cpp:20: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from cmain.cpp:20: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from cmain.cpp:20: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from cmain.cpp:20: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type cmain.cpp:96: warning: type qualifiers ignored on function return type cmain.cpp:107: warning: type qualifiers ignored on function return type cmain.cpp:117: warning: type qualifiers ignored on function return type cmain.cpp:127: warning: type qualifiers ignored on function return type cmain.cpp:269: warning: type qualifiers ignored on function return type cmain.cpp:279: warning: type qualifiers ignored on function return type cmain.cpp:289: warning: type qualifiers ignored on function return type cmain.cpp:299: warning: type qualifiers ignored on function return type cmain.cpp:309: warning: type qualifiers ignored on function return type cmain.cpp:329: warning: type qualifiers ignored on function return type cmain.cpp:678: warning: type qualifiers ignored on function return type compiling em.cpp cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++ In file included from project.h:149, from em.cpp:23: binder.h:35: warning: type qualifiers ignored on function return type In file included from project.h:150, from em.cpp:23: em.h:84: warning: type qualifiers ignored on function return type em.h:85: warning: type qualifiers ignored on function return type em.h:86: warning: type qualifiers ignored on function return type em.h:88: warning: type qualifiers ignored on function return type em.h:89: warning: type qualifiers ignored on function return type em.h:90: warning: type qualifiers ignored on function return type em.h:91: warning: type qualifiers ignored on function return type em.h:93: warning: type qualifiers ignored on function return type em.h:99: warning: type qualifiers ignored on function return type em.h:116: warning: type qualifiers ignored on function return type em.h:125: warning: type qualifiers ignored on function return type In file included from project.h:154, from em.cpp:23: eventmachine.h:46: warning: type qualifiers ignored on function return type eventmachine.h:47: warning: type qualifiers ignored on function return type eventmachine.h:48: warning: type qualifiers ignored on function return type eventmachine.h:50: warning: type qualifiers ignored on function return type eventmachine.h:65: warning: type qualifiers ignored on function return type eventmachine.h:66: warning: type qualifiers ignored on function return type eventmachine.h:67: warning: type qualifiers ignored on function return type eventmachine.h:68: warning: type qualifiers ignored on function return type In file included from project.h:154, from em.cpp:23: eventmachine.h:103: warning: type qualifiers ignored on function return type eventmachine.h:105: warning: type qualifiers ignored on function return type eventmachine.h:108: warning: type qualifiers ignored on function return type em.cpp: In member function 'bool EventMachine_t::_RunEpollOnce()': em.cpp:578: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp:578: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp: In member function 'bool EventMachine_t::_RunSelectOnce()': em.cpp:974: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp:974: warning: 'int rb_thread_select(int, fd_set*, fd_set*, fd_set*, timeval*)' is deprecated (declared at /home/eventhub/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/intern.h:379) em.cpp: At global scope: em.cpp:1057: warning: type qualifiers ignored on function return type em.cpp:1079: warning: type qualifiers ignored on function return type em.cpp:1265: warning: type qualifiers ignored on function return type em.cpp:1338: warning: type qualifiers ignored on function return type em.cpp:1510: warning: type qualifiers ignored on function return type em.cpp:1593: warning: type qualifiers ignored on function return type em.cpp:1856: warning: type qualifiers ignored on function return type em.cpp:1982: warning: type qualifiers ignored on function return type em.cpp:2046: warning: type qualifiers ignored on function return type em.cpp:2070: warning: type qualifiers ignored on function return type em.cpp:2142: warning: type qualifiers ignored on function return type em.cpp:2361: fatal error: error writing to /tmp/ccdlOK0T.s: No space left on device compilation terminated. make: *** [em.o] Error 1 Gem files will remain installed in /home/eventhub/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-1.0.1 for inspection. Results logged to /home/eventhub/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-1.0.1/ext/gem_make.out Any thoughts? I read a lot of different ways to solve this issue, but none of them worked. Thanks

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >