Date: 2014.07.02
Location: Base
--------------------------------------------------------------------------------
first, what is the API
The API (application programming Interface) is ubiquitous in modern software to provide a logical interface for the functionality of a component while hiding the implementation details inside the module. Is the abstraction of the problem, and how the customer interacts with the software component that solves the problem. Overall: TheAPI is a well-defined interface that can provide specific services to other software.
An API that reads an image, for example, might simply provide a loadimage () function that takes a file name as a parameter and then returns a 2-dimensional array of pixels, all of which are hidden under this seemingly simple interface for all file formats and data compression details. The client code can be called by invoking the API's public interface.
--------------------------------------------------------------------------------
second, the API in C + +
The APIs in C + + typically include one or more header files that have been assisted by documents. A specific implementation of a particular API is typically a library file that can be linked to an end-user program, such as a. lib file under Windows, or a dynamic-link library, such as a. dll file under Windows.
For the term API, engineers also prefer to expand to abstract programming interface--abstraction programming interfaces. The elements it contains are summarized as follows:
A. header file: A set of. h header files. The header file defines an interface that enables client code to compile the interface. The Open source API also includes the source code (. cpp file) of the API implementation.
B. Class Library: One or more static or dynamic library files that provide a concrete implementation of the API, where client code can link their code with these library files to add functionality to their applications.
C. Documentation: How to use the API's overview information.
For example:
The well-known Win32 API is the Windows operating system API, which is a collection of C functions, data types and constants, including file handling functions, process and thread management functions, functions to create graphical user interfaces, functions to interact with the network, and so on. The Win32 API is a pure C API, but the typical representative of the API in C api,c++ that we can use in a C + + program is STL, which includes a set of container classes. An iterator that iterates over the elements in a container and the various algorithms that act on the container. STL provides a logical interface for manipulating element collection tasks without exposing the algorithm to implement any details internally.
the general sentence:. an API is a logical interface for software components that hides the internal details required to implement this interface .
When designing the API, because the API describes the software that other engineers use to build their applications, the API must have good design, documentation, regression testing, and stability between releases.
--------------------------------------------------------------------------------
third, the level of the API
The size of the API is arbitrary, as small as a function, as large as a collection of multiple classes. Provides access to any schema-level functionality, from the underlying operating system invocation to the GUI toolkit. For example, common APIs are:
3.1 Operating system APIs
Each operating system must provide a set of standard APIs to make it easier for programmers to invoke system-level services. For example: several api,fork (), Getpid (), Kill (), and so on for process operations in the POSIX API. The Win32 API has CreateProcess (), GetCurrentProcess () and terminateprocess () functions as appropriate. These are very low-level APIs that must be stable and robust, or it could cause many programs to crash.
3.2 Language API
such as printf () in the C standard library, scanf () and fopen () and the C + + Standard Template Library, the container type std::string, Std::vector,std::set,std::map; iterators also have many APIs such as generic algorithms.
3.3 Image API3.4 Tri-D image API3.5 Graphics for interface API
The typical representative is probably the familiar Qt.