当前位置:  编程技术>综合
本页文章导读:
    ▪as3 TextField自动调整高度      测试时用的代码 var string:String = new String(); string = "●本节教学的重点是有理数的概念.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正.........
    ▪How to create RESTful WCF Service      /*by garcon1986*/ Based on my last post about how to create, host, test and consume WCF Service, here we will discover how to create RESTful WCF Service. “Representational State Transfer (REST) is a style of software architecture for distributed s.........
    ▪C++编程调试秘笈----读书笔记(4)       四、指针 造成内存泄露的大多原因都是因为分配了空间但是没有进行释放的结果。但是这样并不会引发错误 一般来说,解决这个问题的有很多种方法,比如com、boost的智能指针,都在某一种.........

[1]as3 TextField自动调整高度
    来源: 互联网  发布时间: 2013-11-07

测试时用的代码

var string:String = new String();
string = "●本节教学的重点是有理数的概念.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.";
putWord(getHeight(string)+14,string);
function getHeight(string:String):Number
{
	var MenuTxt_tmp:TextField = new TextField();
	var MenuTxt_TextFormat:TextFormat = new TextFormat();
	MenuTxt_tmp.name = "toom";
	MenuTxt_tmp.width = 160;
	MenuTxt_tmp.text = string;

	MenuTxt_tmp.multiline = true;

	MenuTxt_tmp.wordWrap = true;//自动换行

	MenuTxt_TextFormat.leading = 7;
	MenuTxt_TextFormat.font = "宋体";
	MenuTxt_TextFormat.size = 14;
	MenuTxt_tmp.setTextFormat(MenuTxt_TextFormat);
	return MenuTxt_tmp.textHeight;
}
function putWord(wordHeight:Number,string:String):void
{
	var MenuTxt_tmp:TextField = new TextField();
	var MenuTxt_TextFormat:TextFormat = new TextFormat();
	MenuTxt_tmp.name = "tom";
	MenuTxt_tmp.x = 100;
	MenuTxt_tmp.y = 100;
	MenuTxt_tmp.width = 160;
	MenuTxt_tmp.height = wordHeight;
	MenuTxt_tmp.text = string;
	MenuTxt_tmp.multiline = true;
	MenuTxt_tmp.wordWrap = true;
	MenuTxt_TextFormat.leading = 7;
	MenuTxt_TextFormat.font = "宋体";
	MenuTxt_TextFormat.size = 14;
	MenuTxt_tmp.setTextFormat(MenuTxt_TextFormat);
	addChild(MenuTxt_tmp);
}


实际项目中用的代码。注意把字体的高度加上来

var string:String = new String();
string = "●本节教学的重点是有理数的概念.\n●建立正数、负数的概念对学生来说是数学抽象思维的一次重大飞跃,是本节教学的难点.";


var MenuTxt_tmp:TextField = new TextField();
var MenuTxt_TextFormat:TextFormat = new TextFormat();
MenuTxt_tmp.name = "tom";
MenuTxt_tmp.x = 100;
MenuTxt_tmp.y = 100;
MenuTxt_tmp.width = 160;
MenuTxt_tmp.text = string;
MenuTxt_tmp.multiline = true;
MenuTxt_tmp.wordWrap = true;
MenuTxt_TextFormat.leading = 7;
MenuTxt_TextFormat.font = "宋体";
MenuTxt_TextFormat.size = 14;
MenuTxt_tmp.setTextFormat(MenuTxt_TextFormat);
MenuTxt_tmp.height = MenuTxt_tmp.textHeight+14;//注意把字体的size加上来
addChild(MenuTxt_tmp);


作者:ComeOnTom 发表于2013-1-7 4:36:28 原文链接
阅读:61 评论:0 查看评论

    
[2]How to create RESTful WCF Service
    来源: 互联网  发布时间: 2013-11-07

/*by garcon1986*/

Based on my last post about how to create, host, test and consume WCF Service, here we will discover how to create RESTful WCF Service.

“Representational State Transfer (REST) is a style of software architecture for distributed systems such as the World Wide Web. REST has emerged as a predominant Web service design model.” from wiki

“Those principles of REST service are:
User agents interact with resources, and resources are anything that can be named and represented. Each resource can be addressed via a unique Uniform Resource Identifier (URI).
Interaction with resources (located through their unique URIs) is accomplished using a uniform interface of the HTTP standard verbs (GET, POST, PUT, and DELETE). Also important in the interaction is the declaration of the resource's media type, which is designated using the HTTP Content-Type header. (XHTML, XML, JPG, PNG, and JSON are some well-known media types.)
Resources are self-descriptive. All the information necessary to process a request on a resource is contained inside the request itself (which allows services to be stateless).
Resources contain links to other resources (hyper-media).” from microsoft


We don't need to change our class "HelloWorldService", so it should always be:

namespace MyWCFServices
{
    /// <summary>
    /// Create a service class and implement service interface
    /// </summary>
    public class HelloWorldService : IHelloWorldService
    {
        public string GetMessage(string name)
        {
            return "Hello world from " + name + "!";
        }

        public string GetPerson(string person)
        {
            return "Person name :" + person + "!";
        }
    }
}

While, the inteface "IHelloWorldService", should be modified.

using System.ServiceModel; //used for ServiceContract. it contains the types necessary to build Windows Communication Foundation (WCF) service and client applications.
using System.ServiceModel.Web;

namespace MyWCFServices
{
    [ServiceContract]
    public interface IHelloWorldService
    {
        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, 
            BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/XML/{name}")]
        string GetMessage(string name);

        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/JSON/{person}")]
        string GetPerson(string person);
    }
}

The content of "HelloWorldService.svc" should always be :

<!--Host web service-->
<%@ServiceHost Service="MyWCFServices.HelloWorldService" %>

And then we should modify the web.config of "HostDevServer"

<?xml version="1.0" encoding="utf-8"?>

<!--
  Pour plus d'informations sur la configuration de votre application ASP.NET, consultez
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <!--Root node of config file-->
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

  <system.serviceModel>
    <!--Top node of WCF Service-->
    <behaviors>
      <serviceBehaviors>
        <!--Specify the bahaviors of a service-->
        <behavior name="MyServiceTypeBehaviors">
          <!-- httpGetEnabled Enable other programs locate the metadata of this web service, 
          client applications can't generate proxy and use web service without medatadata-->
          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="REST"> <!-- Important -->
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <!--List hosted WCF Services in this web site-->
      <!--Each service has its name, behavior and endpoint-->
      <service name="MyWCFServices.HelloWorldService" behaviorConfiguration="MyServiceTypeBehaviors">
        <!--Here wsHttpBinding should be replaced by webHttpBinding for REST Service, and behaviorConfiguration should be "REST" as defined in <endpointBehaviors>-->
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="REST" contract="MyWCFServices.IHelloWorldService"/>
        <!--this endpoint is for metadata exchange-->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

We need to run the service in "HostDevServer" before we test in browser.

Firstly we'll test the first method "GetMessage", 



Then, we test the second method "GetPerson",



I hope this helps! Enjoy coding!


reference: 

http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

http://msdn.microsoft.com/en-us/magazine/dd315413.aspx

http://en.wikipedia.org/wiki/Representational_state_transfer




作者:garcon1986 发表于2013-1-7 4:33:39 原文链接
阅读:61 评论:0 查看评论

    
[3]C++编程调试秘笈----读书笔记(4)
    来源: 互联网  发布时间: 2013-11-07

四、指针

造成内存泄露的大多原因都是因为分配了空间但是没有进行释放的结果。但是这样并不会引发错误

一般来说,解决这个问题的有很多种方法,比如com、boost的智能指针,都在某一种情况下对这种问题提供了解决方案。下面来探讨两种情况的指针

但我们可以建立一个自己的smart point,同时也需要考虑三种情况:

1.是否允许对smart point进行复制,如果是,在smart point中的多份拷贝中,到底有哪一个负责删除它们共同指向的对象(com是最后一个)

2.smart point是否表示指向一个对象的指针,或者表示指向一个对象数组的指针(即它应该使用带方括号的还是不带方括号的delete操作符)

3.smart point是否对应于一个常量指针或一个非常量指针

出于上述的三个情况,有以下两种smart point可以满足:

1.引用计数指针(又称共享指针,也就是com中的smart point)

2.作用域指针

这两种smart point的不同之处在于引用计数指针可以被复制,而作用域指针不能被复制。但是,作用域指针的效率更高。

引用计数指针:

scpp_refcountptr.h:

#ifndef __SCCP_SCOPEDPTR_H__
#define __SCCP_SCOPEDPTR_H__

#include "scpp_assert.h"

namespace scpp
{
	template <typename T>
	class RefCountPtr
	{
	public:
		explicit RefCountPtr(T* p = NULL)
		{
			Create(p);
		}

		RefCountPtr(const RefCountPtr<T>& rhs)
		{
			Copy(rhs);
		}

		RefCountPtr<T>& operator = (const RefCountPtr<T>& rhs)
		{
			if (ptr_ != rhs.ptr_)
			{
				Kill();
				Copy(rhs);
			}

			return *this;
		}

		RefCountPtr<T>& operator = (T *p)
		{
			if (ptr_ != p)
			{
				Kill();
				Create(p);
			}

			return *this;
		}

		~RefCountPtr()
		{
			std::cout << "kill" << std::endl;
			Kill();
		}

	public:
		T* Get() const { return ptr_; }

		T* operator ->() const
		{
			std::cout << "in this" << std::endl;
			SCPP_TEST_ASSERT(ptr_ != NULL, "Attempt to use operator -> on NULL pointer.");
			return ptr_;
		}

		T& operator *() const
		{
			SCPP_TEST_ASSERT(ptr_ != NULL, "Attempt to use operator -> on NULL pointer.");
			return *ptr_;
		}

	private:
		void Create(T* p)
		{
			ptr_ = p;
			if (ptr_ != NULL)
			{
				refCount_ = new int;
				*refCount_ = 1;
			}
			else
			{
				refCount_ = NULL;
			}
		}

		void Copy(const RefCountPtr<T>& rhs)
		{
			ptr_ = rhs.ptr_;
			refCount_ = rhs.refCount_;
			if (refCount_ != NULL)
			{
				++(*refCount_);
			}
		}

		void Kill()
		{
			if (refCount_ != NULL)
			{
				if (--(*refCount_) == 0)
				{
					delete ptr_;
					ptr_ = NULL;
					delete refCount_;
					refCount_ = NULL;
				}
			}
		}
	private:
		T* ptr_;
		int* refCount_;
	};
} // namespace scpp

#endif // __SCCP_SCOPEDPTR_H__

测试代码(vs2012+win7环境):

// debug.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "scpp_assert.h"
#include "iostream"
#include "scpp_vector.h"
#include "scpp_array.h"
#include "scpp_matrix.h"
#include "algorithm"
#include "scpp_types.h"
#include "scpp_refcountptr.h"

#define STUDENTAGE 10

class Student
{
public:
	Student(int age) : age_(age)
	{
	}
	void ShowAge()
	{
		std::cout << "my age is : " << age_ << std::endl;
	}
private:
	int age_;
};

int _tmain(int argc, _TCHAR* argv[])
{
	scpp::RefCountPtr<Student> smartPoint(new Student(STUDENTAGE));
	scpp::RefCountPtr<Student> smartPoint2;

	smartPoint2 = smartPoint;								//@test:赋值操作符
	smartPoint = NULL;
	smartPoint2->ShowAge();

	scpp::RefCountPtr<Student> smartPoint3(smartPoint2);	//@test:拷贝构造函数
	smartPoint2 = NULL;
	smartPoint3->ShowAge();

	scpp::RefCountPtr<Student> *smartPoint4;				//@test:引用
	smartPoint4 = &smartPoint3;
	smartPoint4->Get()->ShowAge();

	Student studen3 = *smartPoint3;							//@test:Get()
	studen3.ShowAge();
	smartPoint3 = NULL;

	Student *student4 = new Student(STUDENTAGE);			//@使用方式
	scpp::RefCountPtr<Student> smartPoint5;
	smartPoint5 = student4;
	smartPoint5->ShowAge();

	return 0;
}

作用域指针:

如果不打算复制智能指针(因此拷贝构造函数和赋值操作符被声明为私有),只是想保证被分配的资源将被正确地回收时使用这种方式,将会减少计数指针保存技术的int*的空间

scpp_scopedptr.h:

#ifndef __SCCP_SCOPEDPTR_H__
#define __SCCP_SCOPEDPTR_H__

#include "scpp_assert.h"

namespace scpp
{
	template <typename T>
	class ScopedPtr
	{
	public:
		explicit ScopedPtr(T* p = NULL)
			: ptr_(p)
		{

		}

		ScopedPtr<T>& operator = (T* p)
		{
			if (ptr_ != p)
			{
				delete ptr_;
				ptr_ = p;
			}

			return *this;
		}

		~ScopedPtr()
		{
			delete ptr_;
		}

		T* operator -> () const
		{
			SCPP_TEST_ASSERT(ptr_ != NULL, "Attempt to use operator -> on NULL pointer.");
			return ptr_;
		}

		T& operator * () const
		{
			SCPP_TEST_ASSERT(ptr_ != NULL, "Attempt to use operator -> on NULL pointer.");
			return *ptr_;
		}

		T* Release()
		{
			T* p = ptr_;
			ptr_ = NULL;
			return p;
		}

	private:
		T* ptr_;

		ScopedPtr(const ScopedPtr<T>& rhs);
		ScopedPtr<T>& operator = (const ScopedPtr<T>& rhs);
	};
} // namespace scpp

#endif // __SCPP_SCOPEDPTR_HPP_INCLUDED__

测试代码(vs2012+win7环境):

#include "stdafx.h"
#include "scpp_assert.h"
#include "iostream"
#include "scpp_vector.h"
#include "scpp_array.h"
#include "scpp_matrix.h"
#include "algorithm"
#include "scpp_types.h"
#include "scpp_refcountptr.h"
#include "scpp_scopedptr.h"

#define STUDENTAGE 10

class Student
{
public:
	Student(int age) : age_(age)
	{
	}
	void ShowAge()
	{
		std::cout << "my age is : " << age_ << std::endl;
	}
private:
	int age_;
};

int _tmain(int argc, _TCHAR* argv[])
{
	scpp::ScopedPtr<Student> smartPoint(new Student(STUDENTAGE));	//@test:构造函数
	smartPoint->ShowAge();


	scpp::ScopedPtr<Student> smartPoint2;							//@test:实体类的赋值操作
	Student *student = new Student(STUDENTAGE);						//@使用方式
	smartPoint2 = student;

	smartPoint2->ShowAge();											//@test:重载->

	(*smartPoint2).ShowAge();										//@test:重载*

	scpp::ScopedPtr<Student> *smartPoint3;							//@test:Release()
	smartPoint3 = &smartPoint2;
	Student *students2;
	students2 = smartPoint3->Release();								//释放smartpoint保存原来的地址
	students2->ShowAge();

	return 0;
}

综合两个smart point的例子,使用方式都是“每次使用new操作符创建一个对象时,立即把结果赋值给一个智能指针”。

以上的两个smart point其实都没解决一个问题,就是当我们的对象是const的情况,怎么办?分析一下这种情况,传入smart point的对象是一个const,这以为这里面的一些成员变量是无法修改的,所以有了下面的一种半智能的smart point:

scpp_ptr.h:

#ifndef __SCCP_PTR_H__
#define __SCCP_PTR_H__

#include "scpp_assert.h"

namespace scpp
{
	template <typename T>
	class Ptr
	{
	public:
		explicit Ptr(T *p = NULL)
			: ptr_(p)
		{

		}

		T* Get() co      
    
最新技术文章:
▪error while loading shared libraries的解決方法    ▪版本控制的极佳实践    ▪安装多个jdk,多个tomcat版本的冲突问题
▪简单选择排序算法    ▪国外 Android资源大集合 和个人学习android收藏    ▪.NET MVC 给loading数据加 ajax 等待loading效果
▪http代理工作原理(3)    ▪关注细节-TWaver Android    ▪Spring怎样把Bean实例暴露出来?
▪java写入excel2007的操作    ▪http代理工作原理(1)    ▪浅谈三层架构
▪http代理工作原理(2)    ▪解析三层架构……如何分层?    ▪linux PS命令
▪secureMRT Linux命令汉字出现乱码    ▪把C++类成员方法直接作为线程回调函数    ▪weak-and算法原理演示(wand)
▪53个要点提高PHP编程效率    ▪linux僵尸进程    ▪java 序列化到mysql数据库中
▪利用ndk编译ffmpeg    ▪活用CSS巧妙解决超长文本内容显示问题    ▪通过DBMS_RANDOM得到随机
▪CodeSmith 使用教程(8): CodeTemplate对象    ▪android4.0 进程回收机制    ▪仿天猫首页-产品分类
▪从Samples中入门IOS开发(四)------ 基于socket的...    ▪工作趣事 之 重装服务器后的网站不能正常访...    ▪java序列化学习笔记
▪Office 2010下VBA Addressof的应用    ▪一起来学ASP.NET Ajax(二)之初识ASP.NET Ajax    ▪更改CentOS yum 源为163的源
▪ORACLE 常用表达式    ▪记录一下,AS3反射功能的实现方法    ▪u盘文件系统问题
▪java设计模式-观察者模式初探    ▪MANIFEST.MF格式总结    ▪Android 4.2 Wifi Display核心分析 (一)
▪Perl 正则表达式 记忆方法    ▪.NET MVC 给loading数据加 ajax 等待laoding效果    ▪java 类之访问权限
▪extjs在myeclipse提示    ▪xml不提示问题    ▪Android应用程序运行的性能设计
▪sharepoint 2010 自定义列表启用版本记录控制 如...    ▪解决UIScrollView截获touch事件的一个极其简单有...    ▪Chain of Responsibility -- 责任链模式
▪运行skyeye缺少libbfd-2.18.50.0.2.20071001.so问题    ▪sharepoint 2010 使用sharepoint脚本STSNavigate方法实...    ▪让javascript显原型!
▪kohana基本安装配置    ▪MVVM开发模式实例解析    ▪sharepoint 2010 设置pdf文件在浏览器中访问
▪spring+hibernate+事务    ▪MyEclipse中文乱码,编码格式设置,文件编码格...    ▪struts+spring+hibernate用jquery实现数据分页异步加...
▪windows平台c++开发"麻烦"总结    ▪Android Wifi几点    ▪Myeclipse中JDBC连接池的配置
▪优化后的冒泡排序算法    ▪elasticsearch RESTful搜索引擎-(java jest 使用[入门])...    ▪MyEclipse下安装SVN插件SubEclipse的方法
▪100个windows平台C++开发错误之七编程    ▪串口转以太网模块WIZ140SR/WIZ145SR 数据手册(版...    ▪初识XML(三)Schema
▪Deep Copy VS Shallow Copy    ▪iphone游戏开发之cocos2d (七) 自定义精灵类,实...    ▪100个windows平台C++开发错误之八编程
▪C++程序的内存布局    ▪将不确定变为确定系列~Linq的批量操作靠的住...    ▪DIV始终保持在浏览器中央,兼容各浏览器版本
▪Activity生命周期管理之三——Stopping或者Restarti...    ▪《C语言参悟之旅》-读书笔记(八)    ▪C++函数参数小结
▪android Content Provider详解九    ▪简单的图片无缝滚动效果    ▪required artifact is missing.
▪c++编程风格----读书笔记(1)    ▪codeforces round 160    ▪【Visual C++】游戏开发笔记四十 浅墨DirectX教程...
▪【D3D11游戏编程】学习笔记十八:模板缓冲区...    ▪codeforces 70D 动态凸包    ▪c++编程风格----读书笔记(2)
▪Android窗口管理服务WindowManagerService计算Activity...    ▪keytool 错误: java.io.FileNotFoundException: MyAndroidKey....    ▪《HTTP权威指南》读书笔记---缓存
▪markdown    ▪[设计模式]总结    ▪网站用户行为分析在用户市场领域的应用
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3